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
### Changes
Add support for Connected Accounts to SPA JS:
- Bump SPA-JS to include auth0/auth0-spa-js#1422
- Add a new `connectAccountWithRedirect` method that redirects the
application to the `/connect` endpoint on the auth server (similar
mechanics to the logging in with the `/authorize` endpoint)
- Update the playground to enabled testing Connected Accounts
<img width="50%" height="50%" alt="image"
src="https://github.com/user-attachments/assets/7aecbc87-5f1b-47ee-a868-0d7c05a3ba56"
/>
### References
https://auth0team.atlassian.net/browse/AGAI-157
### Testing
Manual testing steps and demo video are in ESD-52475
- [x] This change adds unit test coverage
- [ ] This change adds integration test coverage
(integration tests are not possible since oidc-provider does not support
the proprietary Auth0 connect flow)
- [x] This change has been tested on the latest version of the
platform/language
### Checklist
- [x] I have read the [Auth0 general contribution
guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [x] I have read the [Auth0 Code of
Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
- [x] All code quality tools/guidelines have been run/followed
Copy file name to clipboardExpand all lines: EXAMPLES.md
+87-1Lines changed: 87 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,8 @@
9
9
-[Use with Auth0 organizations](#use-with-auth0-organizations)
10
10
-[Protecting a route with a claims check](#protecting-a-route-with-a-claims-check)
11
11
-[Device-bound tokens with DPoP](#device-bound-tokens-with-dpop)
12
-
-[Using Multi Resource Refresh Tokens]()
12
+
-[Using Multi Resource Refresh Tokens](#using-multi-resource-refresh-tokens)
13
+
-[Connect Accounts for using Token Vault](#connect-accounts-for-using-token-vault)
13
14
14
15
## Use with a Class Component
15
16
@@ -597,3 +598,88 @@ MRRT is disabled by default. To enable it, set the `useMrrt` option to `true` wh
597
598
> [!IMPORTANT]
598
599
> In order MRRT to work, it needs a previous configuration setting the refresh token policies.
599
600
> Visit [configure and implement MRRT.](https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token/configure-and-implement-multi-resource-refresh-token)
601
+
602
+
## Connect Accounts for using Token Vault
603
+
604
+
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.
605
+
606
+
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.
607
+
608
+
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.
609
+
610
+
This is particularly useful for applications that require access to different resources on behalf of a user, like AI Agents.
611
+
612
+
### Configure the SDK
613
+
614
+
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.
615
+
616
+
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.
617
+
618
+
The My Account API requires DPoP tokens, so we also need to enable DPoP.
619
+
620
+
```jsx
621
+
<Auth0Provider
622
+
domain="YOUR_AUTH0_DOMAIN"
623
+
clientId="YOUR_AUTH0_CLIENT_ID"
624
+
authorizationParams={{
625
+
redirect_uri:window.location.origin,
626
+
audience:'<AUTH0 API IDENTIFIER>'// The API that will use the tokens from the Token Vault
627
+
}}
628
+
useRefreshTokens={true}
629
+
useMrrt={true}
630
+
useDpop={true}
631
+
>
632
+
<App />
633
+
</Auth0Provider>
634
+
```
635
+
636
+
### Login to the application
637
+
638
+
Use the login methods to authenticate to the application and get a refresh and access token for the API.
639
+
640
+
```jsx
641
+
constLogin= () => {
642
+
const { loginWithRedirect } =useAuth0();
643
+
return<button onClick={() =>loginWithRedirect({
644
+
authorizationParams: {
645
+
audience:'<AUTH0 API IDENTIFIER>', // The API that will use the tokens from the Token Vault
646
+
scope:'openid profile email offline_access read:calendar'// Make sure you get a Refresh Token as you're using MRRT to get access to the My Account API
647
+
}
648
+
})}>Login</button>;
649
+
};
650
+
```
651
+
652
+
### Connect to a third party account
653
+
654
+
Use the new `connectAccountWithRedirect` method to redirect the user to the third party Identity Provider to connect their account.
When the redirect completes, the user will be returned to the application and the tokens from the third party Identity Provider will be stored in the Token Vault.
670
+
671
+
```jsx
672
+
<Auth0Provider
673
+
// ...
674
+
onRedirectCallback={(appState) => {
675
+
if (appState.connectedAccount) {
676
+
console.log(`You've connected to ${appState.connectedAccount.connection}`);
You can now [call the API](#calling-an-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.
0 commit comments