Forum Xamarin.Android

Login with Xamarin.Auth using Microsoft Account does not redirect

abitzanabitzan Member ✭✭
edited January 2020 in Xamarin.Android

Hello everyone!

I built an app where it is possible to login with Google or your Microsoft account.
I followed the respective Tutorial on how to use Xamarin.Auth for Google services, which worked out perfectly.
With the help of the Microsoft OAUTH workflow Tutorial, I was able to register my app in Azure, and implement the Login like this:

                  var authenticator = new OAuth2Authenticator(
                Constants.ClientID,
                null,
                "https://graph.microsoft.com/User.Read",
                new Uri("https://login.microsoftonline.com/common/oauth2/v2.0/authorize"),
                new Uri("https://login.microsoftonline.com/common/oauth2/nativeclient"),
                new Uri("https://login.microsoftonline.com/common/oauth2/v2.0/token"),
                null,
                true);


                authenticator.Completed += OnAuthCompleted;
                authenticator.Error += OnAuthError;

                AuthenticationState.Authenticator = authenticator;

                var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
                presenter.Login(authenticator);

I also applied a listener, to see if the response works

authenticator.Completed += OnAuthCompleted;

Now if I press the Microsoft login button, the correct website opens in the native browser, I fill in the credentials and get fowarded to an empty page

However, the URL of this empty page is already filled with the code, as stated in the Microsoft OAUTH workflow Tutorial

The URL looks like this:

Which is exactly how it should look like, but I get no response inside the app. Seems like the default redirect URL for mobile devices

is not working?

My expected behaviour is that the app opens again and the Completed event is fired, as it already works with the Google login.
Unfortunately the Microsoft docs only feature a Google example.

How do I get the code stated in the URL inside my app?

Thank you

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Have you configured the redirect process on each platform?
    i.e. on iOS, we need to add a custom url scheme:

    This url must match with the application which is registered on the Google Api Console:

    We also need to configure it in the Constants class:

    public static string iOSRedirectUrl = "<insert iOS redirect URL here>:/oauth2redirect";
    public static string AndroidRedirectUrl = "<insert Android redirect URL here>:/oauth2redirect";
    

    Please follow this documentation:
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/authentication/oauth#ios

Sign In or Register to comment.