You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EXAMPLES.md
+76-10Lines changed: 76 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@
9
9
-[Handling errors](#handling-errors)
10
10
-[Organizations](#organizations)
11
11
-[Standalone Components and a more functional approach](#standalone-components-and-a-more-functional-approach)
12
+
-[Connect Accounts for using Token Vault](#connect-accounts-for-using-token-vault)
12
13
13
14
## Add login to your application
14
15
@@ -157,7 +158,7 @@ import { AuthModule } from '@auth0/auth0-angular';
157
158
clientId: 'YOUR_AUTH0_CLIENT_ID',
158
159
authorizationParams: {
159
160
audience: 'YOUR_AUTH0_API_IDENTIFIER',
160
-
}
161
+
},
161
162
}),
162
163
],
163
164
// ...
@@ -278,7 +279,7 @@ AuthModule.forRoot({
278
279
authorizationParams: {
279
280
audience: 'http://my-api/',
280
281
scope: 'write:orders',
281
-
}
282
+
},
282
283
},
283
284
},
284
285
],
@@ -381,6 +382,7 @@ export class AppComponent {
381
382
```
382
383
383
384
## Standalone components and a more functional approach
385
+
384
386
As of Angular 15, the Angular team is putting standalone components, as well as a more functional approach, in favor of the traditional use of NgModules and class-based approach.
385
387
386
388
There are a couple of difference with how you would traditionally implement our SDK:
@@ -398,18 +400,82 @@ const routes: Routes = [
398
400
path: 'profile',
399
401
component: ProfileComponent,
400
402
canActivate: [authGuardFn],
401
-
}
403
+
},
402
404
];
403
405
404
406
bootstrapApplication(AppComponent, {
405
-
providers: [
406
-
provideRouter(routes),
407
-
provideAuth0(/* Auth Config Goes Here */),
408
-
provideHttpClient(
409
-
withInterceptors([authHttpInterceptorFn])
410
-
)
411
-
]
407
+
providers: [provideRouter(routes), provideAuth0(/* Auth Config Goes Here */), provideHttpClient(withInterceptors([authHttpInterceptorFn]))],
412
408
});
413
409
```
414
410
415
411
Note that `provideAuth0` should **never** be provided to components, but only at the root level of your application.
412
+
413
+
## Connect Accounts for using Token Vault
414
+
415
+
The Connect Accounts feature uses the Auth0 My Account API to allow users to link multiple third party accounts to a single Auth0 user profile.
416
+
417
+
When using Connected Accounts, Auth0 acquires tokens from upstream Identity Providers (like Google) and stores them in a secure [Token Vault](https://auth0.com/docs/secure/tokens/token-vault). These tokens can then be used to access third-party APIs (like Google Calendar) on behalf of the user.
418
+
419
+
The tokens in the Token Vault are then accessible to [Resource Servers](https://auth0.com/docs/get-started/apis) (APIs) configured in Auth0. The SPA application can then issue requests to the API, which can retrieve the tokens from the Token Vault and use them to access the third-party APIs.
420
+
421
+
This is particularly useful for applications that require access to different resources on behalf of a user, like AI Agents.
422
+
423
+
### Configure the SDK
424
+
425
+
The SDK must be configured with an audience (an API Identifier) - this will be the resource server that uses the tokens from the Token Vault.
426
+
427
+
The SDK must also be configured to use refresh tokens and MRRT ([Multiple Resource Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token)) since we will use the refresh token grant to get Access Tokens for the My Account API in addition to the API we are calling.
428
+
429
+
The My Account API requires DPoP tokens, so we also need to enable DPoP.
430
+
431
+
```ts
432
+
AuthModule.forRoot({
433
+
domain: '<AUTH0_DOMAIN>',
434
+
clientId: '<AUTH0_CLIENT_ID>',
435
+
useRefreshTokens: true,
436
+
useMrrt: true,
437
+
useDpop: true,
438
+
authorizationParams: {
439
+
redirect_uri: '<MY_CALLBACK_URL>',
440
+
},
441
+
});
442
+
```
443
+
444
+
### Login to the application
445
+
446
+
Use the login methods to authenticate to the application and get a refresh and access token for the API.
447
+
448
+
```ts
449
+
// Login specifying any scopes for the Auth0 API
450
+
this.auth
451
+
.loginWithRedirect({
452
+
authorizationParams: {
453
+
audience: '<AUTH0_API_IDENTIFIER>',
454
+
scope: 'openid profile email read:calendar',
455
+
},
456
+
})
457
+
.subscribe();
458
+
```
459
+
460
+
### Connect to a third party account
461
+
462
+
Use the `connectAccountWithRedirect` method to redirect the user to the third party Identity Provider to connect their account.
463
+
464
+
```ts
465
+
// Start the connect flow by redirecting to the third party API's login, defined as an Auth0 connection
// additional authorization params to forward to the authorization server
472
+
},
473
+
})
474
+
.subscribe();
475
+
```
476
+
477
+
You can now call the API with your access token and the API can use [Access Token Exchange with Token Vault](https://auth0.com/docs/secure/tokens/token-vault/access-token-exchange-with-token-vault) to get tokens from the Token Vault to access third party APIs on behalf of the user.
478
+
479
+
> **Important**
480
+
>
481
+
> You must enable Offline Access from the Connection Permissions settings to be able to use the connection with Connected Accounts.
0 commit comments