active-directory-xamarin-native-v2: Token cache is not persisted on iOS Simulator

Currently, the user that logged in does not get stored in any way. So this part in OnAppearing never gets executed successfully, because there are no users: var ar = await App.PCA.AcquireTokenSilentAsync(App.Scopes, App.PCA.Users.FirstOrDefault());

Is there any way to persist the logged in user? So that the user does not have to relog every time the application closes and opens.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Closing this issue as @MathildeRoussel added missing steps in the iOS specific considerations

Hello,

I’ve just tested this sample on an iOS simulator (iPhone X 11.3), the AcquireTokenSilentAsync works fine, only you have to specify in your provisioning profile that you want to use the Keychain, and then add in the Entitlements.plist a new key for keychain-access-group with your app bundle id.

After that I’m able to first log in with my password, and when I restart the app I’m already logged in (no need to click on “sign in” and to pick an account)

IMHO there is no bug, you can close this issue and also that one : https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/546

@jennyf19 Sorry , I was just confused with MathildeRoussel comment “the AcquireTokenSilentAsync works fine, only you have to specify in your provisioning profile that you want to use the Keychain” so I was wondering if I need to do something in my Provisioning profile, to get the cached Token working. actually I was always getting an exception “AdalError.FailedToAcquireTokenSilently”, everytime when I restart the app. Thanks to you , I just go through this link :: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Xamarin-ios-specificities, and followed these steps :

  1. Enable Keychain access in your Entitlements.plist file and specify in the Keychain Groups your bundle identifier.
  2. In your project options, on iOS Bundle Signing view, select your Entitlements.plist file for the Custom Entitlements field.
  3. When signing a certificate, make sure XCode uses the same Apple Id. and now I am able to get the cache Token.

Thanks, please let me know if I missed or ignored anything.