Skip to content

Commit 66a9d5f

Browse files
committed
separate web and mobile examples for redirect uri's
1 parent badfebd commit 66a9d5f

File tree

1 file changed

+155
-4
lines changed
  • src/pages/[platform]/build-a-backend/auth/concepts/external-identity-providers

1 file changed

+155
-4
lines changed

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

Lines changed: 155 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Secrets must be created manually with [`ampx sandbox secret`](/[platform]/refere
116116

117117
</Callout>
118118

119+
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
120+
119121
```ts title="amplify/auth/resource.ts"
120122
import { defineAuth, secret } from '@aws-amplify/backend';
121123

@@ -150,6 +152,42 @@ export const auth = defineAuth({
150152
});
151153
```
152154

155+
</InlineFilter>
156+
<InlineFilter filters={["android", "flutter", "swift"]}>
157+
158+
```ts title="amplify/auth/resource.ts"
159+
import { defineAuth, secret } from '@aws-amplify/backend';
160+
161+
export const auth = defineAuth({
162+
loginWith: {
163+
externalProviders: {
164+
google: {
165+
clientId: secret('GOOGLE_CLIENT_ID'),
166+
clientSecret: secret('GOOGLE_CLIENT_SECRET')
167+
},
168+
signInWithApple: {
169+
clientId: secret('SIWA_CLIENT_ID'),
170+
keyId: secret('SIWA_KEY_ID'),
171+
privateKey: secret('SIWA_PRIVATE_KEY'),
172+
teamId: secret('SIWA_TEAM_ID')
173+
},
174+
loginWithAmazon: {
175+
clientId: secret('LOGINWITHAMAZON_CLIENT_ID'),
176+
clientSecret: secret('LOGINWITHAMAZON_CLIENT_SECRET')
177+
},
178+
facebook: {
179+
clientId: secret('FACEBOOK_CLIENT_ID'),
180+
clientSecret: secret('FACEBOOK_CLIENT_SECRET')
181+
},
182+
callbackUrls: ["myapp://callback/"],
183+
logoutUrls: ["myapp://signout/"],
184+
}
185+
}
186+
});
187+
```
188+
189+
</InlineFilter>
190+
153191
You need to now inform your external provider of the newly configured authentication resource and its OAuth redirect URI:
154192

155193
<BlockSwitcher>
@@ -220,6 +258,8 @@ You need to now inform your external provider of the newly configured authentica
220258

221259
You can determine the pieces of data you want to retrieve from each external provider when setting them up in the `amplify/auth/resource.ts` file using `scopes`.
222260

261+
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
262+
223263
```ts title="amplify/auth/resource.ts"
224264
import { defineAuth } from '@aws-amplify/backend';
225265

@@ -242,6 +282,30 @@ export const auth = defineAuth({
242282
});
243283
```
244284

285+
</InlineFilter>
286+
<InlineFilter filters={["android", "flutter", "swift"]}>
287+
288+
```ts title="amplify/auth/resource.ts"
289+
import { defineAuth } from '@aws-amplify/backend';
290+
291+
export const auth = defineAuth({
292+
loginWith: {
293+
externalProviders: {
294+
loginWithAmazon: {
295+
clientId: secret('LOGINWITHAMAZON_CLIENT_ID'),
296+
clientSecret: secret('LOGINWITHAMAZON_CLIENT_SECRET'),
297+
// highlight-next-line
298+
scopes: ['email']
299+
},
300+
callbackUrls: ["myapp://callback/"],
301+
logoutUrls: ["myapp://signout/"],
302+
}
303+
}
304+
});
305+
```
306+
307+
</InlineFilter>
308+
245309
### Attribute mapping
246310

247311
You can map which attributes are mapped between your external identity provider and your users created in Cognito. We will be able to have the best level of protection for developers if we ensure that attribute mappings that would not work are called out by the type system.
@@ -252,6 +316,8 @@ If you specify an attribute in your authentication resource as required, and it
252316

253317
</Callout>
254318

319+
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
320+
255321
```ts title="amplify/auth/resource.ts"
256322
import { defineAuth } from '@aws-amplify/backend';
257323

@@ -276,6 +342,35 @@ export const auth = defineAuth({
276342
}
277343
});
278344
```
345+
346+
</InlineFilter>
347+
<InlineFilter filters={["android", "flutter", "swift"]}>
348+
349+
```ts title="amplify/auth/resource.ts"
350+
import { defineAuth } from '@aws-amplify/backend';
351+
352+
export const auth = defineAuth({
353+
loginWith: {
354+
externalAuthProviders: {
355+
loginWithAmazon: {
356+
clientId: secret('LOGINWITHAMAZON_CLIENT_ID'),
357+
clientSecret: secret('LOGINWITHAMAZON_CLIENT_SECRET'),
358+
// highlight-start
359+
attributeMapping: {
360+
email: 'email'
361+
}
362+
// highlight-end
363+
},
364+
callbackUrls: ["myapp://callback/"],
365+
logoutUrls: ["myapp://signout/"],
366+
}
367+
}
368+
});
369+
```
370+
371+
</InlineFilter>
372+
373+
279374
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
280375
- [Learn more about configuring the React Authenticator component for external providers](https://ui.docs.amplify.aws/react/connected-components/authenticator/configuration#external-providers)
281376
</InlineFilter>
@@ -284,6 +379,8 @@ export const auth = defineAuth({
284379

285380
To setup a OIDC provider, you can configure them in your `amplify/auth/resource.ts` file. For example, if you would like to setup a Microsoft EntraID provider, you can do so as follows:
286381

382+
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
383+
287384
```ts title="amplify/auth/resource.ts"
288385
import { defineAuth, secret } from '@aws-amplify/backend';
289386

@@ -309,6 +406,34 @@ export const auth = defineAuth({
309406
});
310407
```
311408

409+
</InlineFilter>
410+
<InlineFilter filters={["android", "flutter", "swift"]}>
411+
412+
```ts title="amplify/auth/resource.ts"
413+
import { defineAuth, secret } from '@aws-amplify/backend';
414+
415+
export const auth = defineAuth({
416+
loginWith: {
417+
email: true,
418+
externalProviders: {
419+
oidc: [
420+
{
421+
name: 'MicrosoftEntraID',
422+
clientId: secret('MICROSOFT_ENTRA_ID_CLIENT_ID'),
423+
clientSecret: secret('MICROSOFT_ENTRA_ID_CLIENT_SECRET'),
424+
issuerUrl: '<your-issuer-url>',
425+
},
426+
],
427+
callbackUrls: ["myapp://callback/"],
428+
logoutUrls: ["myapp://signout/"],
429+
},
430+
},
431+
});
432+
```
433+
434+
</InlineFilter>
435+
436+
312437
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
313438

314439
Use the `signInWithRedirect` API to initiate sign-in with an OIDC identity provider.
@@ -328,6 +453,8 @@ await signInWithRedirect({
328453

329454
To setup a SAML provider, you can configure them in your `amplify/auth/resource.ts` file. For example, if you would like to setup a Microsoft EntraID provider, you can do so as follows:
330455

456+
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
457+
331458
```ts title="amplify/auth/resource.ts"
332459
import { defineAuth } from '@aws-amplify/backend';
333460

@@ -352,6 +479,33 @@ export const auth = defineAuth({
352479
});
353480
```
354481

482+
</InlineFilter>
483+
<InlineFilter filters={["android", "flutter", "swift"]}>
484+
485+
```ts title="amplify/auth/resource.ts"
486+
import { defineAuth } from '@aws-amplify/backend';
487+
488+
export const auth = defineAuth({
489+
loginWith: {
490+
email: true,
491+
externalProviders: {
492+
saml: {
493+
name: 'MicrosoftEntraIDSAML',
494+
metadata: {
495+
metadataContent: '<your-url-hosting-saml-metadata>', // or content of the metadata file
496+
metadataType: 'URL', // or 'FILE'
497+
},
498+
},
499+
callbackUrls: ["myapp://callback/"],
500+
logoutUrls: ["myapp://signout/"],
501+
},
502+
},
503+
});
504+
```
505+
506+
</InlineFilter>
507+
508+
355509
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
356510

357511
Use the `signInWithRedirect` API to initiate sign-in with a SAML identity provider.
@@ -472,7 +626,6 @@ import { signInWithRedirect } from 'aws-amplify/auth';
472626
signInWithRedirect({
473627
provider: 'Apple'
474628
});
475-
476629
```
477630

478631
### Redirect URLs
@@ -483,7 +636,6 @@ _Sign in_ & _Sign out_ redirect URL(s) are used to redirect end users after the
483636
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.
484637

485638
```ts
486-
import { Amplify } from 'aws-amplify';
487639
import { signOut } from 'aws-amplify/auth';
488640

489641
// Assuming the following URLS were provided manually or via the Amplify configuration file,
@@ -492,10 +644,9 @@ import { signOut } from 'aws-amplify/auth';
492644
signOut({
493645
global: false,
494646
oauth: {
495-
redirectUrl: 'https://authProvider/logout?logout_uri=myDevApp://'
647+
redirectUrl: 'https://authProvider/logout?logout_uri=myapp://'
496648
}
497649
});
498-
499650
```
500651
<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>
501652

0 commit comments

Comments
 (0)