-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: add information about the new signOut redirect url option #7938
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
Changes from 6 commits
2d8df41
313130c
f5bcc08
772acce
188d514
f644e2e
5014e27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. Sanity check: Gen2 doc doesn't have an equivalent page for adding this information? 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. I couldn't find any relevant place. Only relatable location is the signOut page but that's for the common use-case and Gen2 has nothing on signInWithRedirect I believe. 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. Added it here for Gen2. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -739,15 +739,81 @@ function App() { | |
</Block> | ||
</BlockSwitcher> | ||
|
||
### Redirect URLs | ||
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. I think this section is redundant. By examining lines 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. On RN page, we don't have any info on redirects so I thought this will set up some context before diving into multiple redirects. |
||
|
||
If you want to manually configure multiple _Sign in_ & _Sign out_ redirect URL(s), you'll need to pass them in your Amplify configuration. For example: | ||
|
||
```javascript | ||
israx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Amplify.configure({ | ||
Auth: { | ||
Cognito: { | ||
loginWith: { | ||
oauth: { | ||
redirectSignIn: [ | ||
'myDevApp://' | ||
], | ||
redirectSignOut: [ | ||
'myDevApp://', | ||
'myProdApp://' | ||
], | ||
...oauthConfig | ||
} | ||
}, | ||
...userPoolConfig | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
#### Specifying a redirect URL on sign out | ||
If you have multiple redirect urls configured, you may choose to override the default behavior of selecting a redirect url and provide the one of your choosing when calling `signOut`. The provided redirect url should match at least one of the configured redirect urls. If no redirect url is provided to `signOut`, the first item from the the configured redirect urls list that does not contain a http nor https prefix will be picked. | ||
israx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```ts | ||
israx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { Amplify } from 'aws-amplify'; | ||
import { signOut } from 'aws-amplify/auth'; | ||
|
||
Amplify.configure({ | ||
Auth: { | ||
Cognito: { | ||
loginWith: { | ||
oauth: { | ||
redirectSignIn: [ | ||
'myDevApp://' | ||
], | ||
redirectSignOut: [ | ||
'myDevApp://', | ||
'https://oidcProvider/?logout_uri=myDevApp://' | ||
], | ||
...oauthConfig | ||
} | ||
}, | ||
...userPoolConfig | ||
} | ||
} | ||
}); | ||
|
||
function handleSignOut() { | ||
signOut({ | ||
global: false, | ||
oauth: { | ||
redirectUrl: 'https://oidcProvider/?logout_uri=myDevApp://' | ||
} | ||
}); | ||
} | ||
|
||
|
||
``` | ||
<Callout> Irrespective of whether a `redirectUrl` is provided to `signOut`, a URL that does not contain http or https is expected to be present in the configured redirect URL list. This is because iOS requires an appScheme when creating the web session. </Callout> | ||
|
||
</InlineFilter> | ||
|
||
<InlineFilter filters={["javascript", "angular", "nextjs", "react", "vue"]}> | ||
|
||
### Redirect URLs | ||
|
||
For _Sign in Redirect URI(s)_ inputs, you can put one URI for local development and one for production. Example: `http://localhost:3000/` in dev and `https://www.example.com/` in production. The same is true for _Sign out redirect URI(s)_. | ||
For _Sign in Redirect URL(s)_ inputs, you can set one URL for local development and one for production. For example: `http://localhost:3000/` in dev and `https://www.example.com/` in production. The same is true for _Sign out Redirect URL(s)_. | ||
|
||
If you have multiple redirect URI inputs, you'll need to pass them in your Amplify configuration. For example: | ||
If you have multiple redirect URLs, you'll need to pass them in your Amplify configuration. For example: | ||
|
||
```javascript | ||
Amplify.configure({ | ||
|
@@ -772,7 +838,7 @@ Amplify.configure({ | |
}); | ||
``` | ||
|
||
<Accordion title='Full Example using multiple redirect URIs' headingLevel='4' eyebrow='Example'> | ||
<Accordion title='Full Example using multiple redirect URLs' headingLevel='4' eyebrow='Example'> | ||
|
||
<BlockSwitcher> | ||
<Block name="TypeScript"> | ||
|
@@ -943,6 +1009,43 @@ function App() { | |
|
||
</Accordion> | ||
|
||
#### Specifying a redirect URL on sign out | ||
If you have multiple redirect urls configured, you may choose to override the default behavior of selecting a redirect url and provide the one of your choosing when calling `signOut`. The provided redirect url should match at least one of the configured redirect urls. If no redirect url is provided to `signOut`, one will be selected based on the current app domain. | ||
|
||
```ts | ||
import { Amplify } from 'aws-amplify'; | ||
import { signOut } from 'aws-amplify/auth'; | ||
|
||
Amplify.configure({ | ||
Auth: { | ||
Cognito: { | ||
loginWith: { | ||
oauth: { | ||
redirectSignIn: [ | ||
'http://localhost:3000/', | ||
'https://www.example.com/' | ||
], | ||
redirectSignOut: [ | ||
'http://localhost:3000/', | ||
'https://www.example.com/' | ||
], | ||
...oauthConfig | ||
} | ||
}, | ||
...userPoolConfig | ||
} | ||
} | ||
}); | ||
|
||
signOut({ | ||
global: false, | ||
oauth: { | ||
redirectUrl: 'https://www.example.com/' | ||
} | ||
}); | ||
|
||
``` | ||
|
||
### (Required for Multi-Page Applications) Complete Social 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: | ||
|
Uh oh!
There was an error while loading. Please reload this page.