I am currently trying to use a REST
service inside a xamarin.forms
app.
To perform the authentication I use this code:
string consumerKey = "consumer_key";
string consumerSecret = "consumer_secret";
var requestTokenUrl = new Uri("https://service/oauth/request_token");
var authorizeUrl = new Uri("https://dservice/oauth/authorize");
var accessTokenUrl = new Uri("https://service/oauth/access_token");
var callbackUrl = new Uri("customprot://oauth1redirect");
authenticator = new Xamarin.Auth.OAuth1Authenticator(consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, null, true);
authenticator.ShowErrors = true;
authenticator.Completed += Aut_Completed;
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Completed += Presenter_Completed;
authenticator.Error += Authenticator_Error;
presenter.Login(authenticator);
Now, after authenticating the user will be redirected to customprot://oauth1redirect
. To catch this redirection I added a new IntentFilter
(for Android) like this:
[Activity(Label = "OAuthLoginUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[] { "customprot"},
DataPathPrefix = "/oauth1redirect")]
public class OAuthLoginUrlSchemeInterceptorActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Convert Android.Net.Url to Uri
var uri = new Uri(Intent.Data.ToString());
// Load redirectUrl page
Core.Controller.authenticator.OnPageLoading(uri);
Core.Controller.authenticator.OnPageLoaded(uri);
Finish();
}
}
As far as I understood the documentation of xamarin.auth
this will trigger the OAuth1Authenticator
to parse the resulting url to get the authenticated user's credentials, and ultimatley triggering the Completed
or Error
event. But suprisingly nothing happens: no event is called or error raised. As this makes debugging harder, I do not really know how to solve this issue. Therefore, I am looking for suggestings about the cause of the issue and possible solutions, too.
Edit: Just to make this clearer: The OnCreate
method of the intent is called, but executing the OnPageLoading
method does not raise the Completed
nor the Error
event of the authenticator.
Edit2: here is the code of my callbacks (I created a breakpoint inside each of them, and the debugger does not break at them or raise an exception, so I am quite sure, that the callbacks are not called at all).
private static void Presenter_Completed(object sender, Xamarin.Auth.AuthenticatorCompletedEventArgs e)
{
throw new NotImplementedException();
}
private static void Aut_Completed(object sender, Xamarin.Auth.AuthenticatorCompletedEventArgs e)
{
throw new NotImplementedException();
}