Skip to content

Commit 6c6ce5c

Browse files
chore: add information about the new signOut redirect url option (#7938)
* chore: add redirect section to sigout * chore: convert URI to URL * chore: review comments
1 parent 3092127 commit 6c6ce5c

File tree

2 files changed

+115
-25
lines changed
  • src/pages
    • [platform]/build-a-backend/auth/concepts/external-identity-providers
    • gen1/[platform]/build-a-backend/auth/add-social-provider

2 files changed

+115
-25
lines changed

src/pages/[platform]/build-a-backend/auth/concepts/external-identity-providers/index.mdx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ await signInWithRedirect({
368368
</InlineFilter>
369369

370370
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
371+
371372
{/* @TODO refactor with connect-your-frontend/sign-in */}
372373
## Set up your frontend
373374

@@ -387,6 +388,29 @@ await signInWithRedirect({
387388
});
388389
```
389390

391+
### Redirect URLs
392+
393+
_Sign in_ & _Sign out_ redirect URL(s) are used to redirect end users after the sign in or sign out operation has occurred. You may want to specify multiple URLs for various use-cases such as having different URLs for development/ production or redirect users to an intermediate URL before returning them to the app.
394+
395+
#### Specifying a redirect URL on sign out
396+
If you have multiple sign out 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.
397+
398+
```ts
399+
import { Amplify } from 'aws-amplify';
400+
import { signOut } from 'aws-amplify/auth';
401+
402+
// Assuming the following URLS were provided manually or via the Amplify configuration file,
403+
// redirectSignOut: 'http://localhost:3000/,https://authProvider/logout?logout_uri=https://mywebsite.com/'
404+
405+
signOut({
406+
global: false,
407+
oauth: {
408+
redirectUrl: 'https://authProvider/logout?logout_uri=https://mywebsite.com/'
409+
}
410+
});
411+
412+
```
413+
390414
</InlineFilter>
391415
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
392416

@@ -430,6 +454,53 @@ When you import and use the `signInWithRedirect` function, it will add a listene
430454
</Accordion>
431455
</InlineFilter>
432456

457+
<InlineFilter filters={["react-native"]}>
458+
459+
## Set up your frontend
460+
461+
<Callout info>
462+
463+
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.
464+
465+
</Callout>
466+
467+
Use the `signInWithRedirect` API to initiate sign-in with an external identity provider.
468+
469+
```ts title="src/my-client-side-js.js"
470+
import { signInWithRedirect } from 'aws-amplify/auth';
471+
472+
signInWithRedirect({
473+
provider: 'Apple'
474+
});
475+
476+
```
477+
478+
### Redirect URLs
479+
480+
_Sign in_ & _Sign out_ redirect URL(s) are used to redirect end users after the sign in or sign out operation has occurred. You may want to specify multiple URLs for various use-cases such as having different URLs for development/ production or redirect users to an intermediate URL before returning them to the app.
481+
482+
#### Specifying a redirect URL on sign out
483+
If you have multiple sign out 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.
484+
485+
```ts
486+
import { Amplify } from 'aws-amplify';
487+
import { signOut } from 'aws-amplify/auth';
488+
489+
// Assuming the following URLS were provided manually or via the Amplify configuration file,
490+
// redirectSignOut: 'myDevApp://,https://authProvider/logout?logout_uri=myDevApp://'
491+
492+
signOut({
493+
global: false,
494+
oauth: {
495+
redirectUrl: 'https://authProvider/logout?logout_uri=myDevApp://'
496+
}
497+
});
498+
499+
```
500+
<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>
501+
502+
</InlineFilter>
503+
433504
## Next steps
434505

435506
- [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)

src/pages/gen1/[platform]/build-a-backend/auth/add-social-provider/index.mdx

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -739,40 +739,40 @@ function App() {
739739
</Block>
740740
</BlockSwitcher>
741741
742-
</InlineFilter>
742+
### Redirect URLs
743743
744-
<InlineFilter filters={["javascript", "angular", "nextjs", "react", "vue"]}>
744+
_Sign in_ & _Sign out_ redirect URL(s) are used to redirect end users after the sign in or sign out operation has occurred. You may want to specify multiple URLs for various use-cases such as having different URLs for development/ production or redirect users to an intermediate URL before returning them to the app.
745745
746-
### Redirect URLs
746+
#### Specifying a redirect URL on sign out
747+
If you have multiple sign out 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.
747748
748-
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)_.
749+
```ts
750+
import { Amplify } from 'aws-amplify';
751+
import { signOut } from 'aws-amplify/auth';
749752

750-
If you have multiple redirect URI inputs, you'll need to pass them in your Amplify configuration. For example:
753+
// Assuming the following URLS were provided manually or via the Amplify configuration file,
754+
// redirectSignOut: 'myDevApp://,https://authProvider/logout/?logout_uri=myDevApp://'
751755

752-
```javascript
753-
Amplify.configure({
754-
Auth: {
755-
Cognito: {
756-
loginWith: {
757-
oauth: {
758-
redirectSignIn: [
759-
'http://localhost:3000/',
760-
'https://www.example.com/'
761-
],
762-
redirectSignOut: [
763-
'http://localhost:3000/',
764-
'https://www.example.com/'
765-
],
766-
...oauthConfig
767-
}
768-
},
769-
...userPoolConfig
770-
}
756+
signOut({
757+
global: false,
758+
oauth: {
759+
redirectUrl: 'https://authProvider/logout/?logout_uri=myDevApp://'
771760
}
772761
});
762+
763+
773764
```
765+
<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>
766+
767+
</InlineFilter>
768+
769+
<InlineFilter filters={["javascript", "angular", "nextjs", "react", "vue"]}>
770+
771+
### Redirect URLs
774772
775-
<Accordion title='Full Example using multiple redirect URIs' headingLevel='4' eyebrow='Example'>
773+
_Sign in_ & _Sign out_ redirect URL(s) are used to redirect end users after the sign in or sign out operation has occurred. You may want to specify multiple URLs for various use-cases such as having different URLs for development (`http://localhost:3000/`) production (`https://www.example.com/`) or redirect users to an intermediate URL before returning them to the app.
774+
775+
<Accordion title='Full Example using multiple redirect URLs' headingLevel='4' eyebrow='Example'>
776776

777777
<BlockSwitcher>
778778
<Block name="TypeScript">
@@ -943,6 +943,25 @@ function App() {
943943

944944
</Accordion>
945945

946+
#### Specifying a redirect URL on sign out
947+
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.
948+
949+
```ts
950+
import { Amplify } from 'aws-amplify';
951+
import { signOut } from 'aws-amplify/auth';
952+
953+
// Assuming the following URLS were provided manually or via the Amplify configuration file,
954+
// redirectSignOut: 'http://localhost:3000/,https://www.example.com/'
955+
956+
signOut({
957+
global: false,
958+
oauth: {
959+
redirectUrl: 'https://www.example.com/'
960+
}
961+
});
962+
963+
```
964+
946965
### (Required for Multi-Page Applications) Complete Social Sign In after Redirect
947966

948967
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:

0 commit comments

Comments
 (0)