Skip to content

Commit 772acce

Browse files
chore: add same sections to Gen2 docs
1 parent f5bcc08 commit 772acce

File tree

2 files changed

+155
-3
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

+155
-3
lines changed

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

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,72 @@ await signInWithRedirect({
387387
});
388388
```
389389

390+
### Redirect URIs
391+
392+
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)_.
393+
394+
If you have multiple redirect URI inputs, you'll need to pass them in your Amplify configuration. For example:
395+
396+
```javascript
397+
Amplify.configure({
398+
Auth: {
399+
Cognito: {
400+
loginWith: {
401+
oauth: {
402+
redirectSignIn: [
403+
'http://localhost:3000/',
404+
'https://www.example.com/'
405+
],
406+
redirectSignOut: [
407+
'http://localhost:3000/',
408+
'https://www.example.com/'
409+
],
410+
...oauthConfig
411+
}
412+
},
413+
...userPoolConfig
414+
}
415+
}
416+
});
417+
```
418+
419+
#### Specifying a redirect URI on sign out
420+
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.
421+
422+
```ts
423+
import { Amplify } from 'aws-amplify';
424+
import { signOut } from 'aws-amplify/auth';
425+
426+
Amplify.configure({
427+
Auth: {
428+
Cognito: {
429+
loginWith: {
430+
oauth: {
431+
redirectSignIn: [
432+
'http://localhost:3000/',
433+
'https://www.example.com/'
434+
],
435+
redirectSignOut: [
436+
'http://localhost:3000/',
437+
'https://www.example.com/'
438+
],
439+
...oauthConfig
440+
}
441+
},
442+
...userPoolConfig
443+
}
444+
}
445+
});
446+
447+
signOut({
448+
global: false,
449+
oauth: {
450+
redirectUrl: 'https://www.example.com/'
451+
}
452+
});
453+
454+
```
455+
390456
</InlineFilter>
391457
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
392458

@@ -430,6 +496,94 @@ When you import and use the `signInWithRedirect` function, it will add a listene
430496
</Accordion>
431497
</InlineFilter>
432498

499+
<InlineFilter filters={["react-native"]}>
500+
501+
## Set up your frontend
502+
503+
<Callout info>
504+
505+
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.
506+
507+
</Callout>
508+
509+
Use the `signInWithRedirect` API to initiate sign-in with an external identity provider.
510+
511+
```ts title="src/my-client-side-js.js"
512+
import { signInWithRedirect } from 'aws-amplify/auth';
513+
514+
await signInWithRedirect({
515+
provider: 'Apple'
516+
});
517+
```
518+
519+
### Redirect URIs
520+
521+
If you want to manually configure multiple _Sign in_ & _Sign out_ redirect URI(s), you'll need to pass them in your Amplify configuration. For example:
522+
523+
```javascript
524+
Amplify.configure({
525+
Auth: {
526+
Cognito: {
527+
loginWith: {
528+
oauth: {
529+
redirectSignIn: [
530+
'myDevApp://'
531+
],
532+
redirectSignOut: [
533+
'myDevApp://',
534+
'myProdApp://'
535+
],
536+
...oauthConfig
537+
}
538+
},
539+
...userPoolConfig
540+
}
541+
}
542+
});
543+
```
544+
545+
#### Specifying a redirect URI on sign out
546+
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.
547+
548+
```ts
549+
import { Amplify } from 'aws-amplify';
550+
import { signOut } from 'aws-amplify/auth';
551+
552+
Amplify.configure({
553+
Auth: {
554+
Cognito: {
555+
loginWith: {
556+
oauth: {
557+
redirectSignIn: [
558+
'myDevApp://'
559+
],
560+
redirectSignOut: [
561+
'myDevApp://',
562+
'https://oidcProvider/?logout_uri=myDevApp://'
563+
],
564+
...oauthConfig
565+
}
566+
},
567+
...userPoolConfig
568+
}
569+
}
570+
});
571+
572+
function handleSignOut() {
573+
signOut({
574+
global: false,
575+
oauth: {
576+
redirectUrl: 'https://oidcProvider/?logout_uri=myDevApp://'
577+
}
578+
});
579+
}
580+
581+
582+
```
583+
<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>
584+
585+
</InlineFilter>
586+
433587
## Next steps
434588

435589
- [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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,7 @@ function App() {
741741
742742
### Redirect URIs
743743
744-
You can provide multiple _Sign in_ & _Sign out_ redirect URI(s).
745-
746-
If you have multiple redirect URI inputs, you'll need to pass them in your Amplify configuration. For example:
744+
If you want to manually configure multiple _Sign in_ & _Sign out_ redirect URI(s), you'll need to pass them in your Amplify configuration. For example:
747745
748746
```javascript
749747
Amplify.configure({

0 commit comments

Comments
 (0)