Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hectormmg committed Nov 15, 2023
1 parent 2e09ae5 commit d17fc59
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/msal-common/docs/multi-tenant-accounts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Multi-tenant Support in MSAL JS SDKs

> This is an advanced document regarding the handling of accounts to acquire tokens across tenants in the `msal-browser` and `msal-node` SDKs. For basic account information, please review the [Accounts](./accounts.md) document.
> This document is about the handling of multi-tenant accounts to acquire tokens across tenants in the `msal-browser` and `msal-node` SDKs. For basic account information, please review the [Accounts](./accounts.md) document.
## Table of Contents

Expand Down
6 changes: 3 additions & 3 deletions lib/msal-node/docs/accounts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Accounts in MSAL Node

> This is the platform-specific Accounts documentation for `msal-node`. For the general documentation of the `AccountInfo` object structure, please visit the `msal-common` [Accounts document](../../msal-common/docs/Accounts.md).For documentation relating to multi-tenant accounts, please visit the [Multi-tenant Accounts document](../../msal-common/docs/multi-tenant-accounts.md).
> This is the platform-specific Accounts documentation for `msal-node`. For the general documentation of the `AccountInfo` object structure, please visit the `msal-common` [Accounts document](../../msal-common/docs/Accounts.md). For documentation relating to multi-tenant accounts, please visit the [Multi-tenant Accounts document](../../msal-common/docs/multi-tenant-accounts.md).
## Usage

Expand All @@ -18,7 +18,7 @@ For a multiple accounts scenario:

```javascript
// Initiates Acquire Token Silent flow
function callAcquireTokenSilent()
function callAcquireTokenSilent() {
// Find all accounts
const msalTokenCache = myMSALObj.getTokenCache();
const cachedAccounts = await msalTokenCache.getAllAccounts();
Expand All @@ -41,7 +41,7 @@ function callAcquireTokenSilent()
.catch((error) => {
// Error handling
});
});
}
```

### getAccountByHomeId and getAccountByLocalId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ myMSALObj.initialize().then(() => {

function handleResponse() {
// when a filter is passed into getAllAccounts, it returns all cached accounts that match the filter. Use isHomeTenant filter to get the home accounts.
const allAccounts = myMSALObj.getAllAccounts({ tenantId: homeTenant, username: "[email protected]" });
const allAccounts = myMSALObj.getAllAccounts();
console.log("Get all accounts: ", allAccounts);
if (!allAccounts || allAccounts.length < 1) {
return;
Expand Down Expand Up @@ -77,17 +77,15 @@ function signOut(interactionType) {
async function requestGuestToken() {
const currentAcc = myMSALObj.getAccountByHomeId(accountId);
if (currentAcc) {
const response = await getTokenRedirect({ ...guestTenantRequest, account: currentAcc }).catch(error => {
console.log(error);
});

const response = await sso(guestTenantRequest, currentAcc.idTokenClaims.login_hint);
console.log(response);
callMSGraph(graphConfig.graphMeEndpoint, response.accessToken, updateUI);
guestProfileButton.style.display = 'none';
}
}

async function getTokenRedirect(request) {
console.log("Request: ", request);
return await myMSALObj.acquireTokenSilent(request).catch(async (error) => {
console.log("silent token acquisition fails.");
if (error instanceof msal.InteractionRequiredAuthError) {
Expand All @@ -98,4 +96,17 @@ async function getTokenRedirect(request) {
console.error(error);
}
});
}

async function sso(request, loginHint) {
return await myMSALObj.ssoSilent(request, loginHint).catch(async (error) => {
console.log("sso failed");
if (error instanceof msal.InteractionRequiredAuthError) {
// fallback to interaction when silent call fails
console.log("acquiring token using redirect");
myMSALObj.acquireTokenRedirect(request);
} else {
console.error(error);
}
})
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const homeTenant = "72f988bf-86f1-41af-91ab-2d7cd011db47";
const guestTenant = "5d97b14d-c396-4aee-b524-c86d33e9b660"
const homeTenant = "HOME_TENANT_ID";
const guestTenant = "GUEST_TENANT_ID"
const baseAuthority = "https://login.microsoftonline.com"

// Config object to be passed to Msal on creation
const msalConfig = {
auth: {
clientId: "bc77b0a7-16aa-4af4-884b-41b968c9c71a",
clientId: "ENTER_CLIENT_ID",
authority: `${baseAuthority}/${homeTenant}`
},
cache: {
Expand Down

0 comments on commit d17fc59

Please sign in to comment.