2

I'm building an app as Trakt client using Xamarin. To authenticate users, I use Xamarin.Auth because its cross-platform. However, after the authentication succeeds, it doesn't call Completed event handler. The event is only called once I click on the Back button but it returns a null Account object and false IsAuthenticated. I'm wondering if its because the redirect uri is invalid.

Please see my code below.

[assembly: ExportRenderer(typeof(LoginView), typeof(LoginViewRenderer))]
namespace ShowsCalendar.Droid.ViewRenderer
{
public class LoginViewRenderer : PageRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);

        var context = Forms.Context;

        var baseAddress = ConfigHelper.TraktAPIURL;
        var auth = new OAuth2Authenticator(
            clientId: ConfigHelper.ClientID,
            redirectUrl: new Uri("urn:ietf:wg:oauth:2.0:oob"),
            scope: "",
            authorizeUrl: new Uri(baseAddress + "/oauth/authorize?response_type=code")
            );
        auth.AllowCancel = true;
        auth.Completed += AuthenticateCompleted;            
        var intent = auth.GetUI(context);
        context.StartActivity(intent);
    }

    private void AuthenticateCompleted(object sender, AuthenticatorCompletedEventArgs e)
    {
        if (!e.IsAuthenticated)
        {
            return;                
        }
        App.AccessToken = e.Account.Properties["access_token"].ToString();
        AccountStore.Create().Save(e.Account, "Trakt");
    }
}

}

Tùng Trịnh
  • 75
  • 1
  • 4

0 Answers0