-
Notifications
You must be signed in to change notification settings - Fork 1.1k
rework "use existing cognito resources" prose, highlight configuring client libs directly #7806
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
Merged
jacoblogan
merged 5 commits into
aws-amplify:main
from
josefaidt:rework-existing-auth-prose
Aug 7, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1e1973
rework "use existing cognito resources" prose, highlight configuring …
josefaidt b10c7ae
Merge remote-tracking branch 'upstream/main' into rework-existing-aut…
josefaidt 48a8d38
Merge remote-tracking branch 'upstream/main' into rework-existing-aut…
josefaidt fc9f4eb
pivot use existing aws resources page to generalized 'connect _to_'
josefaidt d2bc95f
rm backend snippets in favor of referenceAuth rfc
josefaidt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a redirect, cc @jacoblogan