-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(swift): Fixing Auth category for Gen2 #7576
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
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bcf4eb2
fix(swift): Fixing Auth category for Gen2
harsh62 fb62ed9
Update src/pages/[platform]/build-a-backend/auth/concepts/tokens-and-…
harsh62 5a01df9
Update src/pages/[platform]/build-a-backend/auth/connect-your-fronten…
harsh62 57dc4aa
working on review comments
harsh62 504d0c6
Update src/pages/[platform]/build-a-backend/auth/connect-your-fronten…
harsh62 e2b5328
Update src/pages/[platform]/build-a-backend/auth/connect-your-fronten…
harsh62 24e8cb6
worked on review coments
harsh62 d9429b5
Merge branch 'gen2-auth-doc-fix' of github.com:aws-amplify/docs into …
harsh62 d81a5a8
update based on comments
harsh62 f32188a
fixing the mdx link
harsh62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,70 +276,8 @@ export const auth = defineAuth({ | |
} | ||
}); | ||
``` | ||
|
||
[Learn more about configuring the React Authenticator component for external providers](https://ui.docs.amplify.aws/react/connected-components/authenticator/configuration#external-providers) | ||
|
||
{/* @TODO refactor with connect-your-frontend/sign-in */} | ||
## Set up your frontend | ||
|
||
<Callout info> | ||
|
||
If you are using the [Authenticator component](https://ui.docs.amplify.aws/react/connected-components/authenticator/configuration#external-providers) with Amplify, this feature works without any additional code. The guide below is for writing your own implementation. | ||
|
||
</Callout> | ||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}> | ||
|
||
Use the `signInWithRedirect` API to initiate sign-in with an external identity provider. | ||
|
||
```ts title="src/my-client-side-js.js" | ||
import { signInWithRedirect } from 'aws-amplify/auth'; | ||
|
||
await signInWithRedirect({ | ||
provider: 'Apple' | ||
}); | ||
``` | ||
|
||
</InlineFilter> | ||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}> | ||
|
||
### (Required for Multi-Page Applications) Complete external Sign In after Redirect | ||
|
||
If you are developing a multi-page application, and the redirected page is not the same page that initiated the sign in, you will need to add the following code to the redirected page to ensure the sign in gets completed: | ||
|
||
```ts title="src/my-redirected-page.ts" | ||
import 'aws-amplify/auth/enable-oauth-listener'; | ||
import { getCurrentUser, fetchUserAttributes } from 'aws-amplify/auth'; | ||
import { Hub } from 'aws-amplify/utils'; | ||
|
||
Hub.listen("auth", ({ payload }) => { | ||
switch (payload.event) { | ||
case "signInWithRedirect": | ||
const user = await getCurrentUser(); | ||
const userAttributes = await fetchUserAttributes(); | ||
console.log({user, userAttributes}); | ||
break; | ||
case "signInWithRedirect_failure": | ||
// handle sign in failure | ||
break; | ||
case "customOAuthState": | ||
const state = payload.data; // this will be customState provided on signInWithRedirect function | ||
console.log(state); | ||
break; | ||
} | ||
}); | ||
``` | ||
|
||
<Callout> | ||
|
||
**Note:** The listener only works on the client side in the context of a SSR-enabled project, so ensure to import the listener on the client side only. For example, in a Next.js project, you should add the above import statement to a component that renders on the client side only by `'use client'`. | ||
|
||
</Callout> | ||
|
||
<Accordion eyebrow="Under the hood" headingLevel="4" title="Why external Sign In needs to be explicitly handled for Multi-Page Applications"> | ||
|
||
When you import and use the `signInWithRedirect` function, it will add a listener as a side effect that will complete the external sign in when an end user is redirected back to your app. This works well in a single-page application but in a multi-page application, you might get redirected to a page that doesn't include the listener that was originally added as a side-effect. Hence you must include the specific OAuth listener on your login success page. | ||
|
||
</Accordion> | ||
- [Learn more about configuring the React Authenticator component for external providers](https://ui.docs.amplify.aws/react/connected-components/authenticator/configuration#external-providers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this filter have |
||
</InlineFilter> | ||
|
||
## Configure OIDC provider | ||
|
@@ -429,6 +367,69 @@ await signInWithRedirect({ | |
``` | ||
</InlineFilter> | ||
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}> | ||
{/* @TODO refactor with connect-your-frontend/sign-in */} | ||
## Set up your frontend | ||
|
||
<Callout info> | ||
|
||
If you are using the [Authenticator component](https://ui.docs.amplify.aws/react/connected-components/authenticator/configuration#external-providers) with Amplify, this feature works without any additional code. The guide below is for writing your own implementation. | ||
|
||
</Callout> | ||
|
||
Use the `signInWithRedirect` API to initiate sign-in with an external identity provider. | ||
|
||
```ts title="src/my-client-side-js.js" | ||
import { signInWithRedirect } from 'aws-amplify/auth'; | ||
|
||
await signInWithRedirect({ | ||
provider: 'Apple' | ||
}); | ||
``` | ||
|
||
</InlineFilter> | ||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}> | ||
|
||
### (Required for Multi-Page Applications) Complete external Sign In after Redirect | ||
|
||
If you are developing a multi-page application, and the redirected page is not the same page that initiated the sign in, you will need to add the following code to the redirected page to ensure the sign in gets completed: | ||
|
||
```ts title="src/my-redirected-page.ts" | ||
import 'aws-amplify/auth/enable-oauth-listener'; | ||
import { getCurrentUser, fetchUserAttributes } from 'aws-amplify/auth'; | ||
import { Hub } from 'aws-amplify/utils'; | ||
|
||
Hub.listen("auth", ({ payload }) => { | ||
switch (payload.event) { | ||
case "signInWithRedirect": | ||
const user = await getCurrentUser(); | ||
const userAttributes = await fetchUserAttributes(); | ||
console.log({user, userAttributes}); | ||
break; | ||
case "signInWithRedirect_failure": | ||
// handle sign in failure | ||
break; | ||
case "customOAuthState": | ||
const state = payload.data; // this will be customState provided on signInWithRedirect function | ||
console.log(state); | ||
break; | ||
} | ||
}); | ||
``` | ||
|
||
<Callout> | ||
|
||
**Note:** The listener only works on the client side in the context of a SSR-enabled project, so ensure to import the listener on the client side only. For example, in a Next.js project, you should add the above import statement to a component that renders on the client side only by `'use client'`. | ||
|
||
</Callout> | ||
|
||
<Accordion eyebrow="Under the hood" headingLevel="4" title="Why external Sign In needs to be explicitly handled for Multi-Page Applications"> | ||
|
||
When you import and use the `signInWithRedirect` function, it will add a listener as a side effect that will complete the external sign in when an end user is redirected back to your app. This works well in a single-page application but in a multi-page application, you might get redirected to a page that doesn't include the listener that was originally added as a side-effect. Hence you must include the specific OAuth listener on your login success page. | ||
|
||
</Accordion> | ||
</InlineFilter> | ||
|
||
## Next steps | ||
|
||
- [Learn how to sign in with external providers](/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/#sign-in-with-external-provider) | ||
- [Learn how to sign in with external providers](/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/#sign-in-with-an-external-identity-provider) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.