-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework "use existing cognito resources" prose, highlight configuring …
…client libs directly (#7806) * rework "use existing cognito resources" prose, highlight configuring client libs directly * pivot use existing aws resources page to generalized 'connect _to_' * rm backend snippets in favor of referenceAuth rfc
- Loading branch information
Showing
4 changed files
with
152 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
src/pages/[platform]/start/connect-existing-aws-resources/index.mdx
This file was deleted.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
src/pages/[platform]/start/connect-to-aws-resources/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; | ||
import { Card } from '@aws-amplify/ui-react'; | ||
|
||
export const meta = { | ||
title: 'Connect to AWS resources', | ||
description: 'You can use Amplify client libraries to connect directly to your AWS resources', | ||
platforms: [ | ||
'android', | ||
'angular', | ||
'flutter', | ||
'javascript', | ||
'nextjs', | ||
'react', | ||
'react-native', | ||
'swift', | ||
'vue' | ||
] | ||
}; | ||
|
||
export async function getStaticPaths() { | ||
return getCustomStaticPath(meta.platforms); | ||
} | ||
|
||
export function getStaticProps(context) { | ||
return { | ||
props: { | ||
platform: context.params.platform, | ||
meta | ||
} | ||
}; | ||
} | ||
|
||
Amplify client libraries provide you with the flexibility to directly connect your application to AWS resources such as AWS AppSync, Amazon Cognito, Amazon S3, and more. | ||
|
||
To get started, client libraries must be _configured_. This is typically done by using the [`amplify_outputs.json` file](/[platform]/reference/amplify_outputs) generated by the Amplify backend tooling, however using the client libraries does not require backend resources to be created by Amplify. | ||
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}> | ||
|
||
For JavaScript-based applications, the client library can be configured by using the generated outputs file: | ||
|
||
```ts title="src/main.ts" | ||
import { Amplify } from "aws-amplify" | ||
import outputs from "../amplify_outputs.json" | ||
|
||
Amplify.configure(outputs) | ||
``` | ||
|
||
Or by configuring the library directly by passing a [`ResourcesConfig`](https://aws-amplify.github.io/amplify-js/api/interfaces/aws_amplify.index.ResourcesConfig.html) object. For example, to configure the client library for use with Amazon Cognito, specify the `Auth` configuration: | ||
|
||
```ts title="src/main.ts" | ||
import { Amplify } from "aws-amplify" | ||
|
||
Amplify.configure({ | ||
Auth: { | ||
Cognito: { | ||
userPoolId: "<your-cognito-user-pool-id>", | ||
userPoolClientId: "<your-cognito-user-pool-client-id>", | ||
identityPoolId: "<your-cognito-identity-pool-id>", | ||
loginWith: { | ||
email: true, | ||
}, | ||
signUpVerificationMethod: "code", | ||
userAttributes: { | ||
email: { | ||
required: true, | ||
}, | ||
}, | ||
allowGuestAccess: true, | ||
passwordFormat: { | ||
minLength: 8, | ||
requireLowercase: true, | ||
requireUppercase: true, | ||
requireNumbers: true, | ||
requireSpecialCharacters: true, | ||
}, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
By configuring the client library, Amplify automates the communication with the underlying AWS resources, and provides a friendly API to author your business logic. In the snippet below, the `signIn` function does not require passing information from your Cognito resource to initiate the sign-in flow. | ||
|
||
```ts title="src/main.ts" | ||
import { signIn } from "aws-amplify/auth" | ||
|
||
await signIn({ | ||
username: "john.doe@example.com", | ||
password: "hunter2", | ||
}) | ||
``` | ||
|
||
</InlineFilter> | ||
<InlineFilter filters={["android", "flutter", "swift"]}> | ||
|
||
For mobile platforms, the client library can be configured by creating an `amplify_outputs.json` file in your project's directory. To get started, create the file and specify your resource configuration: | ||
|
||
```json title="amplify_outputs.json" | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/aws-amplify/amplify-backend/main/packages/client-config/src/client-config-schema/schema_v1.json", | ||
"version": "1", | ||
"auth": { | ||
"user_pool_id": "<your-cognito-user-pool-id>", | ||
"aws_region": "<your-aws-region>", | ||
"user_pool_client_id": "<your-cognito-user-pool-client-id>", | ||
"identity_pool_id": "<your-cognito-identity-pool-id>", | ||
"mfa_methods": [], | ||
"standard_required_attributes": [ | ||
"email" | ||
], | ||
"username_attributes": [ | ||
"email" | ||
], | ||
"user_verification_types": [ | ||
"email" | ||
], | ||
"mfa_configuration": "NONE", | ||
"password_policy": { | ||
"min_length": 8, | ||
"require_lowercase": true, | ||
"require_numbers": true, | ||
"require_symbols": true, | ||
"require_uppercase": true | ||
}, | ||
"unauthenticated_identities_enabled": true | ||
} | ||
} | ||
``` | ||
|
||
</InlineFilter> | ||
|
||
For more information about how to use the Amplify client libraries with existing AWS resources, visit the guides: | ||
|
||
<Columns columns={2}> | ||
<Card variation="outlined"> | ||
[Connect to Cognito](/[platform]/build-a-backend/auth/use-existing-cognito-resources/) | ||
|
||
Connect to Cognito resources using Amplify Auth's client library | ||
</Card> | ||
</Columns> |