You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(swift): Documentation for shared keychain (#7890)
* feat(swift): Documentation for shared keychain
* Remove stray space in shared keychain documentation
Co-authored-by: josef <[email protected]>
* adding team id details
* adding the inline filter back that was accidentally removed
* Update src/pages/[platform]/build-a-backend/auth/advanced-workflows/index.mdx
Co-authored-by: josef <[email protected]>
* Update src/pages/[platform]/build-a-backend/auth/advanced-workflows/index.mdx
Co-authored-by: josef <[email protected]>
* Update src/pages/[platform]/build-a-backend/auth/advanced-workflows/index.mdx
Co-authored-by: josef <[email protected]>
* Update src/pages/[platform]/build-a-backend/auth/advanced-workflows/index.mdx
Co-authored-by: josef <[email protected]>
---------
Co-authored-by: josef <[email protected]>
Co-authored-by: Harshdeep Singh <[email protected]>
1. In Xcode, go to Project Settings → Your Target → Signing & Capabilities
385
+
2. Select +Capability
386
+
3. Add Keychain Sharing capability
387
+
4. Add a keychain group
388
+
5. Repeat for all apps for which you want to share auth state, adding the same keychain group for all of them
389
+
390
+
To move to the shared keychain using this new keychain access group, specify the `accessGroup` parameter when instantiating the `AWSCognitoAuthPlugin`. If a user is currently signed in, they will be signed out when first using the access group:
391
+
392
+
```swift
393
+
let accessGroup =AccessGroup(name: "\(teamID)com.example.sharedItems")
394
+
let secureStoragePreferences =AWSCognitoSecureStoragePreferences(
If you would prefer the user session to be migrated (which will allow the user to continue to be signed in), then specify the `migrateKeychainItemsOfUserSession` boolean in the AccessGroup to be true like so:
403
+
404
+
```swift
405
+
let accessGroup =AccessGroup(
406
+
name: "\(teamID)com.example.sharedItems",
407
+
migrateKeychainItemsOfUserSession: true)
408
+
let secureStoragePreferences =AWSCognitoSecureStoragePreferences(
Sign in a user with any sign-in method within one app that uses this access group. After reloading another app that uses this access group, the user will be signed in. Likewise, signing out of one app will sign out the other app after reloading it.
417
+
418
+
### Migrating to another Shared Keychain
419
+
420
+
To move to a different access group, update the name parameter of the AccessGroup to be the new access group. Set `migrateKeychainItemsOfUserSession` to `true` to migrate an existing user session under the previously used access group.
421
+
422
+
### Migrating from a Shared Keychain
423
+
424
+
If you'd like to stop sharing state between this app and other apps, you can set the access group to be `AccessGroup.none` or `AccessGroup.none(migrateKeychainItemsOfUserSession: true)` if you'd like the session to be migrated.
425
+
426
+
### Retrieving Team ID
427
+
428
+
First, ensure your Info.plist has the `AppIdentifierPrefix` key:
429
+
430
+
```xml title="Info.plist"
431
+
<?xml version="1.0" encoding="UTF-8"?>
432
+
<!DOCTYPEplist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
433
+
<plistversion="1.0">
434
+
<dict>
435
+
<key>AppIdentifierPrefix</key>
436
+
<string>$(AppIdentifierPrefix)</string>
437
+
</dict>
438
+
</plist>
439
+
```
440
+
441
+
Then, you can retrieve the team ID from your Info.plist:
0 commit comments