Skip to content

Commit c2f2ca2

Browse files
fix(JS/RN/Flutter): update docs to include switcher for adding auth via CLI or existing resources (aws-amplify#5219)
* update docs to include switch for CLI and existing resources when adding authentication * fix flutter page with proper "existing resources" code sample * fix to file type and minor visual improvement of code sample * add preamble after "Set Up Backend Resources" * add back in the 'Identify User' title/reference in directory.js (out of scope for this PR, saving for Analytics updates overall). * Updates to remove config/dependencies within Blockswitcher, additional PR feedback implemented. * space added for spell check error * New block add for 3 options (2 CLI and 1 Manual config) for Auth backend resources. * Further refinement of blocks and verbiage. Add 3rd Manual Config block for Flutter & mobile. * fixes to create new fragments for Flutter/iOS/Android pages * add change to js preamble * fixes to links that navigating to wrong platform, general feedback from PR Reviews, and added of existing AWS resource links. * Revert callouts * remove a comma that leads to invalid JSON string * revert "jsx" to "dart" for code block * Update src/fragments/lib/auth/js/getting-started.mdx Co-authored-by: Bannon Tanner <[email protected]> * Update src/fragments/lib/auth/android/getting_started/50_configureBackend.mdx Following new Rule #21 for indentation Co-authored-by: Bannon Tanner <[email protected]> * Update src/fragments/lib/auth/flutter/getting_started/70_configureBackend.mdx Co-authored-by: Bannon Tanner <[email protected]> * Update src/fragments/lib/auth/ios/getting_started/50_configureBackend.mdx Co-authored-by: Bannon Tanner <[email protected]> * Update src/fragments/lib/auth/js/getting-started.mdx Rule 21 Co-authored-by: Bannon Tanner <[email protected]> --------- Co-authored-by: Bannon Tanner <[email protected]>
1 parent 33c334c commit c2f2ca2

File tree

15 files changed

+645
-95
lines changed

15 files changed

+645
-95
lines changed

src/directory/directory.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,6 @@ const directory = {
245245
route: '/lib/auth/getting-started',
246246
filters: ['android', 'flutter', 'ios', 'js', 'react-native']
247247
},
248-
{
249-
title: 'Create or re-use existing backend',
250-
route: '/lib/auth/start',
251-
filters: ['js', 'react-native']
252-
},
253248
{
254249
title: 'Sign up, Sign in & Sign out',
255250
route: '/lib/auth/emailpassword',
@@ -374,11 +369,6 @@ const directory = {
374369
title: 'Under the hood',
375370
route: '/lib/auth/overview',
376371
filters: ['android', 'ios', 'js', 'react-native']
377-
},
378-
{
379-
title: 'Use existing Amazon Cognito resources',
380-
route: '/lib/auth/existing-resources',
381-
filters: ['android', 'flutter', 'ios']
382372
}
383373
]
384374
},
@@ -1159,11 +1149,6 @@ const directory = {
11591149
title: 'Under the hood',
11601150
route: '/lib-v1/auth/overview',
11611151
filters: ['android', 'ios']
1162-
},
1163-
{
1164-
title: 'Use existing Amazon Cognito resources',
1165-
route: '/lib-v1/auth/existing-resources',
1166-
filters: ['android', 'ios']
11671152
}
11681153
]
11691154
},

src/fragments/lib-v1/auth/existing-resources.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import nativeCommon0 from "/src/fragments/lib-v1/auth/native_common/existing_res
2424
- **Region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
2525
- **Auth**:
2626
- **Default**:
27-
- **authenticationFlowType**: The authentication flow type, takes values `USER_SRP_AUTH`, `CUSTOM_AUTH`. Default is `USER_SRP_AUTH`.
27+
- **authenticationFlowType**: The authentication flow type, takes values `USER_SRP_AUTH`, `CUSTOM_AUTH`, and `USER_PASSWORD_AUTH`. Default is `USER_SRP_AUTH`.
2828
- **OAuth**: Hosted UI Configuration (only include this if using the Hosted UI flow)
2929
- **Scopes:** Scopes should match the scopes enables in Cognito under "App client settings"
3030

3131
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](/lib-v1/project-setup/create-application#n2-install-amplify-libraries).
3232

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

src/fragments/lib-v1/auth/native_common/existing_resources/common.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you are not using the Amplify CLI, a Cognito User Pool and Identity Pool can
3838
"profile",
3939
"aws.cognito.signin.user.admin"
4040
]
41-
},
41+
}
4242
}
4343
}
4444
}

src/fragments/lib-v1/auth/native_common/getting_started/common.mdx

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
The Amplify Auth category provides an interface for authenticating a user. Behind the scenes, it provides the necessary authorization to the other Amplify categories. It comes with default, built-in support for [Amazon Cognito](https://aws.amazon.com/cognito) User Pool and Identity Pool. The Amplify CLI helps you to create and configure the auth category with an authentication provider.
1+
The Amplify Auth category provides an interface for authenticating a user. Behind the scenes, it provides the necessary authorization to the other Amplify categories. It comes with default, built-in support for [Amazon Cognito](https://aws.amazon.com/cognito) User Pool and Identity Pool. The Amplify CLI helps you create and configure the auth category with an authentication provider.
22

33
## Goal
4-
To setup and configure your application with Amplify Auth and go through a simple api to check the current auth session
4+
5+
To setup and configure your application with Amplify Auth and go through a simple api to check the current auth session.
56

67
## Prerequisites
78

@@ -13,37 +14,21 @@ import android1 from "/src/fragments/lib-v1/auth/android/getting_started/10_preR
1314

1415
<Fragments fragments={{android: android1}} />
1516

16-
## Configure Auth Category
17-
18-
To start provisioning auth resources in the backend, go to your project directory and **execute the command**:
19-
20-
```bash
21-
amplify add auth
22-
```
17+
## Set Up Backend Resources
2318

24-
Enter the following when prompted:
25-
```console
26-
? Do you want to use the default authentication and security configuration?
27-
`Default configuration`
28-
? How do you want users to be able to sign in?
29-
`Username`
30-
? Do you want to configure advanced settings?
31-
`No, I am done.`
32-
```
19+
To use Authentication with Amplify, you have the option to set up or import existing Amazon Cognito resources via the Amplify CLI or manually configure them in your application.
3320

34-
To push your changes to the cloud, **execute the command**:
21+
import ios50 from "/src/fragments/lib/auth/ios/getting_started/50_configureBackend.mdx";
3522

36-
```bash
37-
amplify push
38-
```
23+
<Fragments fragments={{ios: ios50}} />
3924

40-
import ios3 from "/src/fragments/lib-v1/auth/ios/getting_started/12_amplifyConfig.mdx";
25+
import android50 from "/src/fragments/lib/auth/android/getting_started/50_configureBackend.mdx";
4126

42-
<Fragments fragments={{ios: ios3}} />
27+
<Fragments fragments={{android: android50}} />
4328

44-
import android4 from "/src/fragments/lib-v1/auth/android/getting_started/12_amplifyConfig.mdx";
29+
import flutter70 from "/src/fragments/lib/auth/flutter/getting_started/70_configureBackend.mdx";
4530

46-
<Fragments fragments={{android: android4}} />
31+
<Fragments fragments={{flutter: flutter70}} />
4732

4833
## Install Amplify Libraries
4934

src/fragments/lib-v1/project-setup/android/use-existing-resources/use-existing-resources.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ Select a category from the following list to view an example `amplifyconfigurati
9090
* See the [Analytics category](/lib-v1/analytics/existing-resources) to use existing AWS Pinpoint resources.
9191
* See the [API (GraphQL) category](/lib-v1/graphqlapi/existing-resources) to use existing AWS AppSync resources.
9292
* See the [API (REST) category](/lib-v1/restapi/existing-resources) to use existing Amazon API Gateway and AWS Lambda resources.
93-
* See the [Authentication category](/lib-v1/auth/existing-resources) to use existing Amazon Cognito resources.
93+
* See the [Authentication category](/lib-v1/auth/getting-started/q/platform/android/#prerequisites) to use existing Amazon Cognito resources.
9494
* See the [Storage category](/lib-v1/storage/existing-resources) to use existing Amazon S3 resources.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Upon completion, `amplifyconfiguration.json` should be updated to reference provisioned backend auth resources. Note that these files should already be a part of your project if you followed the [Project setup walkthrough](/lib/project-setup/create-application).
1+
Upon completion, `amplifyconfiguration.json` should be updated to reference provisioned backend auth resources. Note that these files should already be a part of your project if you followed the [project setup walkthrough](/lib/project-setup/create-application).
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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>

src/fragments/lib/auth/existing-resources.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import flutter0 from "/src/fragments/lib/auth/flutter/existing_resources/10_exis
2626
- **Region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
2727
- **Auth**:
2828
- **Default**:
29-
- **authenticationFlowType**: The authentication flow type, takes values `USER_SRP_AUTH`, `CUSTOM_AUTH`. Default is `USER_SRP_AUTH`.
29+
- **authenticationFlowType**: The authentication flow type, takes values `USER_SRP_AUTH`, `CUSTOM_AUTH`, and `USER_PASSWORD_AUTH`. Default is `USER_SRP_AUTH`.
3030
- **OAuth**: Hosted UI Configuration (only include this if using the Hosted UI flow)
3131
- **Scopes:** Scopes should match the scopes enables in Cognito under "App client settings"
3232

3333
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](/lib/project-setup/create-application#n2-install-amplify-libraries).
3434

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

src/fragments/lib/auth/flutter/existing_resources/10_existingResources.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const amplifyconfig = ''' {
4040
"profile",
4141
"aws.cognito.signin.user.admin"
4242
]
43-
},
43+
}
4444
}
4545
}
4646
}

0 commit comments

Comments
 (0)