1

I am trying to get server managed authentication working with Visual Studio Mobile Center. It uses Azure App Service Authentication. I was able to setup my Facebook Developer account to allow login, then configured it on Mobile Center, and when I go to the mobile center link for auth in a web browser, it works great.

I setup the client side of the authentication identically to Adrian Hall's examples in his book: https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter2/social/#adding-authentication-to-a-mobile-client

When the webview pops up for facebook, it lets me enter credentials, but then crashes when I hit the submit button. This is the stack trace from the application output window:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
[AndroidRuntime]   at System.ThrowHelper.ThrowKeyNotFoundException () [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0 
[AndroidRuntime]   at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x00021] in <8c304e4006094a46a7950338a3b3cb5d>:0 
[AndroidRuntime]   at Microsoft.WindowsAzure.MobileServices.MobileServiceUIAuthentication+<>c__DisplayClass2_0.<LoginAsyncOverride>b__1 (System.Object sender, Xamarin.Auth._MobileServices.AuthenticatorCompletedEventArgs e) [0x00030] in <fe9883f628724025a38f5e1946e5b4c5>:0 
[AndroidRuntime]   at (wrapper delegate-invoke) System.EventHandler`1[Xamarin.Auth._MobileServices.AuthenticatorCompletedEventArgs]:invoke_void_object_TEventArgs (object,Xamarin.Auth._MobileServices.AuthenticatorCompletedEventArgs)
[AndroidRuntime]   at Xamarin.Auth._MobileServices.Authenticator+<>c__DisplayClass22_0.<OnSucceeded>b__0 () [0x00021] in <fe9883f628724025a38f5e1946e5b4c5>:0 
[AndroidRuntime]   at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <a4e9508b230b49a18f145a67e12eb7b8>:0 
[AndroidRuntime]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <a4e9508b230b49a18f145a67e12eb7b8>:0 
[AndroidRuntime]   at (wrapper dynamic-method) System.Object:23f66101-d05c-44cc-a8fe-d50bbc9e59d1 (intptr,intptr)

Tested on latest Xamarin Studio and Visual Studio 2017, using Xamarin.Forms 2.3.3, latest Xamarin.Auth, and latest Azure MobileServicesClient.

Any suggestions on how to debug this? I have break on all exceptions checked and I get an Unhandled Exception with a message of "The given key was not present in the dictionary.", no inner exception or stack trace, then it crashes.

EDIT: Reproduction: https://github.com/brandonrisell/TapFriends

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Brandon Risell
  • 149
  • 2
  • 9
  • Do you mean you could browser at `https://yoursite.azurewebsites.net/.auth/login/facebook` and get the successful authentication page? I followed your sample project, but found the android project could not be compiled successfully, then I added my `UWPLoginProvider` and point the `MobileServiceClient` to my mobile app, it could work (list items, add new item,etc.). Firstly, please try to check `await mobileCenter.LoginAsync()` of your `LoginViewModel` within the shared project and find whether you could get the logged info, then step by step to debug your code and try to find the cause. – Bruce Chen Apr 12 '17 at 08:00
  • The key-not-found is likely to be the response from the service. Can you possibly turn on diagnostic logging at the verbose level in your service and watch the log stream for the auth event. Add any logs that you receive (appropriately edited for private information) so we can see those? – Adrian Hall Apr 12 '17 at 16:41

1 Answers1

2
  1. Open the Azure Portal
  2. Find the resource group for your Mobile Center backend
  3. Open up the Mobile Apps resource
  4. Select Authentication / Authorization
  5. Check that the Token store is turned on.

If it isn't, turn it on, save then restart and recheck.

I think that's the problem. If not, get back to me here and we'll try something else.

Adrian Hall
  • 7,990
  • 1
  • 18
  • 26
  • Thank you so much, this was exactly it. Will I need to turn this on for client managed auth as well, or is this only an issue because I'm doing server managed auth? – Brandon Risell Apr 13 '17 at 03:33
  • Nope - it's needed for both. I'm working on getting this to be the default for future mobile backends. – Adrian Hall Apr 13 '17 at 03:56