1

I'm trying to do authentication on my Android application using Xamarin.Auth. Some time ago, Google made the policy that you cannot do this in an embedded web view (for totally valid reasons).

I'm trying to open the account authentication page in a browser, but keep getting the embedded web view. I understand that isUsingNativeUI needs to be true in the following code:

        _auth = new OAuth2Authenticator(clientId, string.Empty, scope,
                                        new Uri(Constant.AuthorizeUrl),
                                        new Uri(redirectUrl),
                                        new Uri(Constant.AccessTokenUrl),
                                        null,
                                        isUsingNativeUI = true);

At every point in my application, this always equals true.

Elsewhere, I have code that redirects to what should be a browser:

        var authenticator = Auth.GetAuthenticator();
        Intent intent = authenticator.GetUI(this);
        this.StartActivity(intent);

Regardless, I keep getting a dreaded 403 disallowed_useragent error whenever I try to run the project. Is there another element to this that I'm missing?

To my knowledge, setting auth.IsUsingNativeUI = true in the constructor should dictate that it must open in a browser. I've been following this example to try and debug with no success. I even pulled the guy's repo down to my machine and ran it - the Intent variable at the moment of redirection is almost identical.

Could there be something stupid that I'm missing? What else might be going wrong?

R. McManaman
  • 304
  • 2
  • 14
  • Are you testing on an emulator that does not have Chrome installed? – SushiHangover Apr 24 '18 at 00:54
  • 1
    @SushiHangover Yes, however, this isn't a problem for the code that I pulled from the example I linked in my post. I can try installing it, but it hasn't made a difference in two separate chunks of code running on the same emulator. – R. McManaman Apr 24 '18 at 00:55
  • `Chrome CustomTab` is used on via X.Auth on the Android platform thus Chrome needs to be installed otherwise it will downgrade to use `WebView` and thus the 403 error. This of course is not usually a problem on most devices as the G.Apps are factory installed (There are now other browsers that have implemented `CustomTab` and I'm not sure if Xamarin.Auth will use them, but I have have my own Auth library that does...) – SushiHangover Apr 24 '18 at 01:38
  • @SushiHangover Can you explain why the example I provided works fine without chrome installed? – R. McManaman Apr 24 '18 at 02:08
  • Assuming you are getting the `com.android.browser` which is installed on the basic emulator image(s) and all that it is, is a shell on top of `WebView` (which is a part of the Android framework). You can see what package is going to be used by passing the Intent to PackageManager.QueryIntentActivities. If you have Chrome installed it will return com.android.chrome, com.chrome.beta, com.chrome.dev, or com.google.android.apps.chrome (depending upon what you installed from the Play store) – SushiHangover Apr 24 '18 at 02:20

1 Answers1

1

I realize this is an old question, but I had the same issue.

You have to install version 1.5.0.3 of the Xamarin.Auth Nuget package. The newest one (version 1.7.0 right now) doesn't work. You'll have to also install the PCLCrypto nuget package in order to get that version to work.

Strabbi
  • 213
  • 3
  • 7
  • 1.5.0.3 does not work for Facebook. and google work for both version. can you answer this my question. https://stackoverflow.com/questions/69409278/xamarin-auth-dont-fire-completed-after-login-to-facebook-but-google-does – Johnson Duru Oct 04 '21 at 18:53