locked
Authenticating Users with Azure Mobile Apps RRS feed

  • Question

  • User317063 posted

    I've implemented authentication as shown in Authenticating Users with Azure Mobile Apps sample, and I'm trying to use Google to authenticate on Android. The problem is that after I enter my Google email and password, I just get a blank screen. I know it's using the redirect URI because that shows up in the server log. I have set up the credentials with Google as a web application, and the URI is https://appname.azurewebsites.net/.auth/login/google/callback

    It looks like it is redirecting, but it never returns from the LoginAsync() method call in MainActivity.

    Here is the streaming log from the app service. I've left out the authorization codes for the sake of brevity, and replaced them with [xxx]

    2017-12-04T19:23:37  PID[1852] Verbose    Calling into external HTTP endpoint POST https://www.googleapis.com/oauth2/v4/token.

    2017-12-04T19:23:37  PID[1852] Information Login completed for 'richard@appname.com'. Provider: 'google'.

    2017-12-04T19:23:37  PID[1852] Information Redirecting: appname://easyauth.callback/#authorization_code=xxx

    2017-12-04 19:23:05 appname1 GET /tables/ShoeDataItem X-ARR-LOG-ID=1e8924ca-90bf-4cec-baec-db7fc1b09034 443 - 95.147.236.99 ZUMO/4.0+(lang=Managed;+os=Android;+osversion=5.0.1;+arch=Unix;+version=4.0.2.0) - - appname1.azurewebsites.net 200 0 0 828 1107 6812 2017-12-04 19:23:36 appname1 GET /.auth/login/google postloginredirecturl=appname%3A%2F%2Feasyauth.callback%2F&codechallenge=VA0PMFw2F7nULhqSg7VmX2ochtlQgv%2FgtboLiY4QQtg%3D&codechallengemethod=S256&sessionmode=token&X-ARR-LOG-ID=cc171611-fffd-4811-ba87-b23b39daef2a 443 - 95.147.236.99 Mozilla/5.0+(Linux;+Android+5.0.1;+Lenovo+TB3-710F+Build/LRX21M)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/62.0.3202.84+Safari/537.36 ARRAffinity=ed151e667feb9b64a6434c509863703b9b0737e65adeaa86a6fcf3e9e196f835;+AppServiceAuthSession=xxx/gsqhZRAn3xMfSxAJsIAUmUL android-app://appname.Android appname1.azurewebsites.net 302 0 0 1696 2225 343

    2017-12-04 19:23:37 appname1 GET /.auth/login/google/callback state=codechallenge%3DVA0PMFw2F7nULhqSg7VmX2ochtlQgv%252FgtboLiY4QQtg%253D%26codechallengemethod%3DS256%26redir%3Dappname%253A%252F%252Feasyauth.callback%252F%26nonce%3D4781bec2bd34489b910c14bc8e78602120171204192836&code=4/hdaXbT2bcHyO4-cpKKxcAbKtNqGJhq2De49NTvP41ec&authuser=0&session_state=8c12cbe666515b74129e14870264ac30abd86bf7..5a3d&prompt=none&X-ARR-LOG-ID=cbfbbaa7-0cc1-4588-8253-0bb0ea9e7b1a 443 - 95.147.236.99 Mozilla/5.0+(Linux;+Android+5.0.1;+Lenovo+TB3-710F+Build/LRX21M)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/62.0.3202.84+Safari/537.36 ARRAffinity=ed151e667feb9b64a6434c509863703b9b0737e65adeaa86a6fcf3e9e196f835;+AppServiceAuthSession=xxx/gsqhZRAn3xMfSxAJsIAUmUL;+Nonce=w5Fy+a2BCyn4sWEJ4KEbdYAnndwGSUzucclZfQ+8rfvJ6So1d0domT1C5qoE0o10vvfkm0/IYIdW5s+L+Spn7S77UsQCrM9dSHZX6tBZXoVW5uRHBNy1S6KNdQtDdnFh;+AppServiceSessionMode=token android-app://appname.Android appname1.azurewebsites.net 302 0 0 2764

    Can anyone tell me what I'm doing wrong here or give me any guidance with this? Thanks.

    Monday, December 4, 2017 7:37 PM

Answers

  • User317063 posted

    I figured it out, so if this helps anyone:

    1) I'd followed some other advice on StackExchange, and used microsoft.identity.client.BrowserTabActivity instead of com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity in my AndroidManifest.xml, and this was wrong.

    2) In the manifest, the application should include the activity, i.e.

    application android:label="MyApp" android:icon="@drawable/icon" activity android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity" android:launchMode="singleTop" android:noHistory="true" intent-filter action android:name="android.intent.action.VIEW" / category android:name="android.intent.category.DEFAULT" / category android:name="android.intent.category.BROWSABLE" / data android:scheme="myapp" android:host="easyauth.callback" / /intent-filte> /activity /application

    (sorry about the bad formatting without the brackets, but this crappy editor doesn't seem to allow them) I'd inserted the activity after the closing application tag, instead of putting the closing application tag after the /activity tag. Noob error.

    2) In MainActivity, OnCreate(), I'd forgotten to include the call to Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); (Although removing this did not seem to be a problem once the app was actually working.)

    So it should be: protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); App.Init((IAuthenticate)this); LoadApplication(new App()); }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, December 5, 2017 8:21 PM