Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swift): Documentation for shared keychain #7890

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,55 @@ func federateToIdentityPoolsUsingCustomIdentityId() async throws {
}
```

## Keychain Sharing

### Migrating to a Shared Keychain

To use a shared keychain:

1. In Xcode, go to Project Settings → Signing & Capabilities
2. Click +Capability
3. Add Keychain Sharing capability
4. Add a keychain group
5. Repeat for all apps for which you want to share auth state, adding the same keychain group for all of them

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 logged out when first using the access group:

```swift
let accessGroup = AccessGroup(name: "\(teamID).com.example.sharedItems")
let secureStoragePreferences = AWSCognitoSecureStoragePreferences(
accessGroup: accessGroup)
try Amplify.add(
plugin: AWSCognitoAuthPlugin(
secureStoragePreferences: secureStoragePreferences))
try Amplify.configure()
```

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:

```swift
let accessGroup = AccessGroup(
name: "\(teamID).com.example.sharedItems",
migrateKeychainItemsOfUserSession: true)
let secureStoragePreferences = AWSCognitoSecureStoragePreferences(
accessGroup: accessGroup)
try Amplify.add(
plugin: AWSCognitoAuthPlugin(
secureStoragePreferences: secureStoragePreferences))
try Amplify.configure()
```

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.

### Migrating to another Shared Keychain

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.

### Migrating from a Shared Keychain

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.


</InlineFilter>
<InlineFilter filters={['javascript','react-native','angular','nextjs','react','vue']}>
## Subscribing to Events
Expand Down