Page updated Nov 8, 2023

Use existing Amazon Cognito resources

Amplify iOS v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Swift to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for iOS, you can access the documentation here.

If you are using the Amplify CLI, an existing Amazon Cognito User Pool and Identity Pool can be used with the Amplify Libraries by running:

1amplify import auth

For more details, see how to Use an existing Cognito User Pool and Identity Pool.

If you are not using the Amplify CLI, a Cognito User Pool and Identity Pool can be used by referencing them in your amplifyconfiguration.json file.

1{
2 "auth": {
3 "plugins": {
4 "awsCognitoAuthPlugin": {
5 "IdentityManager": {
6 "Default": {}
7 },
8 "CredentialsProvider": {
9 "CognitoIdentity": {
10 "Default": {
11 "PoolId": "[COGNITO IDENTITY POOL ID]",
12 "Region": "[REGION]"
13 }
14 }
15 },
16 "CognitoUserPool": {
17 "Default": {
18 "PoolId": "[COGNITO USER POOL ID]",
19 "AppClientId": "[COGNITO USER POOL APP CLIENT ID]",
20 "Region": "[REGION]"
21 }
22 },
23 "Auth": {
24 "Default": {
25 "authenticationFlowType": "USER_SRP_AUTH",
26 "OAuth": {
27 "WebDomain": "[YOUR COGNITO DOMAIN ]",
28 "AppClientId": "[COGNITO USER POOL APP CLIENT ID]",
29 "SignInRedirectURI": "[CUSTOM REDIRECT SCHEME AFTER SIGN IN, e.g. myapp://]",
30 "SignOutRedirectURI": "[CUSTOM REDIRECT SCHEME AFTER SIGN OUT, e.g. myapp://]",
31 "Scopes": [
32 "phone",
33 "email",
34 "openid",
35 "profile",
36 "aws.cognito.signin.user.admin"
37 ]
38 }
39 }
40 }
41 }
42 }
43 }
44}
  • CredentialsProvider:
    • Cognito Identity:
      • Default:
        • PoolID: ID of the Amazon Cognito Identity Pool (e.g. us-east-1:123e4567-e89b-12d3-a456-426614174000)
        • Region: AWS Region where the resources are provisioned (e.g. us-east-1)
  • CognitoUserPool:
    • Default:
      • PoolId: ID of the Amazon Cognito User Pool (e.g. us-east-1_abcdefghi)
      • AppClientId: ID for the client used to authenticate against the user pool
      • Region: AWS Region where the resources are provisioned (e.g. us-east-1)
  • Auth:
    • Default:
      • authenticationFlowType: The authentication flow type, takes values USER_SRP_AUTH, CUSTOM_AUTH, and USER_PASSWORD_AUTH. Default is USER_SRP_AUTH.
      • OAuth: Hosted UI Configuration (only include this if using the Hosted UI flow)
        • Scopes: Scopes should match the scopes enables in Cognito under "App client settings"

Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see Install Amplify Libraries.

If you are using a Cognito User Pool without a Cognito Identity Pool, you can omit the CredentialsProvider section in the configuration.