Skip to content

Commit 8f3a71e

Browse files
docs: update connected accounts examples
1 parent 61c6359 commit 8f3a71e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

EXAMPLES.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,13 @@ The My Account API requires DPoP tokens, so we also need to enable DPoP.
864864

865865
```ts
866866
AuthModule.forRoot({
867-
domain: '<AUTH0_DOMAIN>',
868-
clientId: '<AUTH0_CLIENT_ID>',
867+
domain: 'YOUR_AUTH0_DOMAIN',
868+
clientId: 'YOUR_AUTH0_CLIENT_ID',
869869
useRefreshTokens: true,
870870
useMrrt: true,
871871
useDpop: true,
872872
authorizationParams: {
873-
redirect_uri: '<MY_CALLBACK_URL>',
873+
redirect_uri: window.location.origin,
874874
},
875875
});
876876
```
@@ -884,7 +884,7 @@ Use the login methods to authenticate to the application and get a refresh and a
884884
this.auth
885885
.loginWithRedirect({
886886
authorizationParams: {
887-
audience: '<AUTH0_API_IDENTIFIER>',
887+
audience: 'YOUR_AUTH0_API_IDENTIFIER',
888888
scope: 'openid profile email read:calendar',
889889
},
890890
})
@@ -913,7 +913,7 @@ When the redirect completes, the user will be returned to the application and th
913913
```ts
914914
ngOnInit() {
915915
this.auth.appState$.subscribe((appState) => {
916-
if (appState.connectedAccount) {
916+
if (appState?.connectedAccount) {
917917
console.log(`You've connected to ${appState.connectedAccount.connection}`);
918918
// Handle the connected account details
919919
// appState.connectedAccount contains: id, connection, access_type, created_at, expires_at
@@ -922,6 +922,27 @@ ngOnInit() {
922922
}
923923
```
924924
925+
### List connected accounts
926+
927+
To retrieve the accounts a user has connected, get an access token for the My Account API and call the `/v1/connected-accounts/accounts` endpoint:
928+
929+
```ts
930+
this.auth
931+
.getAccessTokenSilently({
932+
authorizationParams: {
933+
audience: `https://YOUR_AUTH0_DOMAIN/me/`,
934+
scope: 'read:me:connected_accounts',
935+
},
936+
})
937+
.subscribe(async (token) => {
938+
const res = await fetch(`https://YOUR_AUTH0_DOMAIN/me/v1/connected-accounts/accounts`, {
939+
headers: { Authorization: `Bearer ${token}` },
940+
});
941+
const { accounts } = await res.json();
942+
// accounts contains: id, connection, access_type, scopes, created_at
943+
});
944+
```
945+
925946
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.
926947
927948
> **Important**

0 commit comments

Comments
 (0)