-
Notifications
You must be signed in to change notification settings - Fork 145
Keychain for MSAL on iOS
Token caching is an essential functionality of MSAL SDK. When MSAL signs user in or refreshes the token, it will try to write tokens into iOS keychain. App needs to configure its entitlements correctly, so that MSAL can write cached tokens to iOS keychain.
You can learn more about keychain access groups in Apple documentation
MSAL will use the "com.microsoft.adalcache" access group by default. This is the shared access group used by both MSAL and ADAL SDKs and ensures the best SSO experience between multiple apps from the same publisher.
In order to use the default keychain access group, you need to add the "com.microsoft.adalcache" keychain group into your app's entitlement. You can do so under Project settings -> Capabilities -> Keychain sharing
If you'd like to use a different keychain access group, you can pass your custom group when creating MSALPublicClientApplicationConfig before creating MSALPublicClientApplication:
MSALPublicClientApplicationConfig.cacheConfig.keychainSharingGroup
e.g.
MSALAuthority *authority;
MSALPublicClientApplicationConfig *config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:@"your-client-id"
redirectUri:@"your-redirect-uri"
authority:authority];
config.cacheConfig.keychainSharingGroup = @"custom-group";
If you don't want to use any keychain access group and share SSO state between multiple apps, you can disable keychain sharing by passing the application bundle ID as your keychainGroup.
MSALPublicClientApplicationConfig *b2cApplicationConfig = [[MSALPublicClientApplicationConfig alloc]
initWithClientId:@"your-client-id"
redirectUri:@"your-redirect-uri"
authority:authority];
config.cacheConfig.keychainSharingGroup = [[NSBundle mainBundle] bundleIdentifier];
This normally indicates that keychain hasn't been configured correctly. Please make sure that the keychain access group that has been configured in MSAL matches the ones configured in entitlements.
- Customizing Browsers and WebViews
- Logging
- Sovereign clouds
- B2C
- Auth Telemetry (coming soon)
- MSAL questions, bugs and issues (coming soon)
- Redirect URIs
- Requesting individual claims
- Keychain cache
- SSL issues
- iOS 13 and macOS 10.15 support
- Releases
- Roadmap (coming soon)