|
| 1 | +<BlockSwitcher> |
| 2 | +<Block name="Amplify CLI (Create)"> |
| 3 | + |
| 4 | +> Prerequisites: [Install and configure](/lib/project-setup/prereq/q/platform/android/#install-and-configure-the-amplify-cli) the Amplify CLI in addition to the Amplify libraries and [necessary dependencies](/lib/auth/getting-started/q/platform/android/#install-amplify-libraries). |
| 5 | +
|
| 6 | +To start provisioning auth resources in the backend, go to your project directory and **execute the command**: |
| 7 | + |
| 8 | +```bash |
| 9 | +amplify add auth |
| 10 | +``` |
| 11 | + |
| 12 | +Enter the following when prompted: |
| 13 | +```console |
| 14 | +? Do you want to use the default authentication and security configuration? |
| 15 | + `Default configuration` |
| 16 | +? How do you want users to be able to sign in? |
| 17 | + `Username` |
| 18 | +? Do you want to configure advanced settings? |
| 19 | + `No, I am done.` |
| 20 | +``` |
| 21 | + |
| 22 | +> If you have previously enabled an Amplify category that uses Auth behind the scenes (e.g. API category), you can run the `amplify update auth` command to edit your configuration if needed. |
| 23 | +
|
| 24 | +To push your changes to the cloud, **execute the command**: |
| 25 | + |
| 26 | +```bash |
| 27 | +amplify push |
| 28 | +``` |
| 29 | + |
| 30 | +import android5 from "/src/fragments/lib/auth/android/getting_started/12_amplifyConfig.mdx"; |
| 31 | + |
| 32 | +<Fragments fragments={{android: android5}} /> |
| 33 | + |
| 34 | +</Block> |
| 35 | + |
| 36 | +<Block name="Amplify CLI (Import)"> |
| 37 | + |
| 38 | +> Prerequisites: [Install and configure](/lib/project-setup/prereq/q/platform/android/#install-and-configure-the-amplify-cli) the Amplify CLI in addition to the Amplify libraries and [necessary dependencies](/lib/auth/getting-started/q/platform/android/#install-amplify-libraries). |
| 39 | +
|
| 40 | +To import existing Amazon Cognito resources into your Amplify project, **execute the command**: |
| 41 | + |
| 42 | +```bash |
| 43 | +amplify import auth |
| 44 | +``` |
| 45 | +```console |
| 46 | +? What type of auth resource do you want to import? |
| 47 | + Cognito User Pool and Identity Pool |
| 48 | + Cognito User Pool only |
| 49 | +``` |
| 50 | + |
| 51 | +Once you've selected an option, you'll be able to search for and import an existing Cognito User Pool and Identity Pool (or User Pool only) within your AWS account. The `amplify import auth` command will also do the following: |
| 52 | +- Automatically populate your Amplify Library configuration file (`amplifyconfiguration.json`) with your chosen Amazon Cognito resource information |
| 53 | +- Provide your designated existing Cognito resource as the authentication & authorization mechanism for all auth-dependent categories (API, Storage and more) |
| 54 | +- Enable Lambda functions to access the chosen Cognito resource if you permit it |
| 55 | + |
| 56 | +> If you have previously enabled an Amplify category that uses Auth behind the scenes (e.g. API category), you can run the `amplify update auth` command to edit your configuration if needed. |
| 57 | +
|
| 58 | +After configuring your Authentication options, update your backend and deploy the service by running the `push` command: |
| 59 | + |
| 60 | +```bash |
| 61 | +amplify push |
| 62 | +``` |
| 63 | + |
| 64 | +Now, the authentication service has been deployed and you can start using it. To view the deployed services in your project at any time, go to Amplify Console by running the following command: |
| 65 | + |
| 66 | +```bash |
| 67 | +amplify console |
| 68 | +``` |
| 69 | +For more details, see how to [Use an existing Cognito User Pool and Identity Pool](/cli/auth/import). |
| 70 | + |
| 71 | +</Block> |
| 72 | + |
| 73 | +<Block name="Manual Configuration"> |
| 74 | + |
| 75 | +If you are not using the Amplify CLI, existing Authentication resources from AWS (e.g. Amazon Cognito UserPools or Identity Pools) can be used with the Amplify Libraries by [manually creating a configuration file](/lib/project-setup/use-existing-resources/q/platform/android/#add-an-existing-aws-resource-to-an-android-application) (`amplifyconfiguration.json`) and then updating the associated Plugin within it: |
| 76 | + |
| 77 | +```jsx |
| 78 | +{ |
| 79 | + "auth": { |
| 80 | + "plugins": { |
| 81 | + "awsCognitoAuthPlugin": { |
| 82 | + "IdentityManager": { |
| 83 | + "Default": {} |
| 84 | + }, |
| 85 | + "CredentialsProvider": { |
| 86 | + "CognitoIdentity": { |
| 87 | + "Default": { |
| 88 | + "PoolId": "[COGNITO IDENTITY POOL ID]", |
| 89 | + "Region": "[REGION]" |
| 90 | + } |
| 91 | + } |
| 92 | + }, |
| 93 | + "CognitoUserPool": { |
| 94 | + "Default": { |
| 95 | + "PoolId": "[COGNITO USER POOL ID]", |
| 96 | + "AppClientId": "[COGNITO USER POOL APP CLIENT ID]", |
| 97 | + "Region": "[REGION]" |
| 98 | + } |
| 99 | + }, |
| 100 | + "Auth": { |
| 101 | + "Default": { |
| 102 | + "authenticationFlowType": "USER_SRP_AUTH", |
| 103 | + "OAuth": { |
| 104 | + "WebDomain": "[YOUR COGNITO DOMAIN ]", |
| 105 | + "AppClientId": "[COGNITO USER POOL APP CLIENT ID]", |
| 106 | + "SignInRedirectURI": "[CUSTOM REDIRECT SCHEME AFTER SIGN IN, e.g. myapp://]", |
| 107 | + "SignOutRedirectURI": "[CUSTOM REDIRECT SCHEME AFTER SIGN OUT, e.g. myapp://]", |
| 108 | + "Scopes": [ |
| 109 | + "phone", |
| 110 | + "email", |
| 111 | + "openid", |
| 112 | + "profile", |
| 113 | + "aws.cognito.signin.user.admin" |
| 114 | + ] |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +- **CredentialsProvider**: |
| 125 | + - **Cognito Identity**: |
| 126 | + - **Default**: |
| 127 | + - **PoolID**: ID of the Amazon Cognito Identity Pool (e.g. `us-east-1:123e4567-e89b-12d3-a456-426614174000`) |
| 128 | + - **Region**: AWS Region where the resources are provisioned (e.g. `us-east-1`) |
| 129 | +- **CognitoUserPool**: |
| 130 | + - **Default**: |
| 131 | + - **PoolId**: ID of the Amazon Cognito User Pool (e.g. `us-east-1_abcdefghi`) |
| 132 | + - **AppClientId**: ID for the client used to authenticate against the user pool |
| 133 | + - **Region**: AWS Region where the resources are provisioned (e.g. `us-east-1`) |
| 134 | +- **Auth**: |
| 135 | + - **Default**: |
| 136 | + - **authenticationFlowType**: The authentication flow type, takes values `USER_SRP_AUTH`, `CUSTOM_AUTH`, and `USER_PASSWORD_AUTH`. Default is `USER_SRP_AUTH`. |
| 137 | + - **OAuth**: Hosted UI Configuration (only include this if using the Hosted UI flow) |
| 138 | + - **Scopes:** Scopes should match the scopes enables in Cognito under "App client settings" |
| 139 | + |
| 140 | +If you are using a Cognito User Pool without a Cognito Identity Pool, you can omit the **CredentialsProvider** section in the configuration. |
| 141 | + |
| 142 | +</Block> |
| 143 | +</BlockSwitcher> |
0 commit comments