Skip to content

Commit 79438c0

Browse files
committed
node updates part 1
1 parent 1575696 commit 79438c0

15 files changed

+448
-145
lines changed

msal-javascript-conceptual/node/accounts.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ ms.reviewer: dmwendia,cwerner, owenrichards, kengaderdus
1515

1616
# Accounts in MSAL Node
1717

18+
This article shows you how to use the `msal-node` library to access cached accounts in your Node.js application. The APIs, `getAllAccounts()`, `getAccountByHomeId()`, and `getAccountByLocalId()` are covered
19+
20+
## Prerequisites
21+
22+
- [Node.js](https://nodejs.org/en/download/)
23+
1824
## Usage
1925

2026
The `msal-node` library provides the following different APIs to access cached accounts:
@@ -25,7 +31,7 @@ The `msal-node` library provides the following different APIs to access cached a
2531

2632
The following are usage examples for each API:
2733

28-
### getAllAccounts
34+
### `getAllAccounts`
2935

3036
For a multiple accounts scenario:
3137

@@ -57,7 +63,7 @@ function callAcquireTokenSilent()
5763
});
5864
```
5965

60-
### getAccountByHomeId and getAccountByLocalId
66+
### `getAccountByHomeId` and `getAccountByLocalId`
6167

6268
For a single account scenario, the `homeAccountId` or `localAccountId` must be obtained from the initial `AuthResponse` object received from a non-silent authorization flow, such as the `Auth Code` flow.
6369

@@ -113,7 +119,8 @@ async function getResource() {
113119
}
114120
```
115121

116-
## Notes
122+
For a multiple accounts scenario, please should modify the [sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/silent-flow/index.js) (in `/graphCall` route) to list all cached accounts and choose a specific account. You may also need to customize the related view templates and `handlebars` template params.
123+
124+
## See also
117125

118-
* The current msal-node silent-flow [sample](../../../samples/msal-node-samples/silent-flow) has a working single account scenario that uses `getAccountByHomeId()`.
119-
* If you have a multiple accounts scenario, please modify the [sample](../../../samples/msal-node-samples/silent-flow/index.js) (in `/graphCall` route) to list all cached accounts and choose a specific account. You may also need to customize the related view templates and `handlebars` template params.
126+
* The current msal-node silent-flow [sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/silent-flow) has a working single account scenario that uses `getAccountByHomeId()`.

msal-javascript-conceptual/node/brokering.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ ms.reviewer: dmwendia,cwerner, owenrichards, kengaderdus
1515

1616
# Acquiring Device Bound Tokens
1717

18-
MSAL Node supports acquiring tokens from the native token broker. When using the native broker refresh tokens are bound to the device on which they are acquired on and are not accessible by `msal-node` or the application. This provides a higher level of security that cannot be achieved by `msal-node` alone.
19-
20-
## Supported Environment
21-
22-
This feature is currently only supported on Windows.
18+
MSAL Node supports acquiring tokens from the native token broker. When using the native broker refresh tokens are bound to the device on which they are acquired on and are not accessible by `msal-node` or the application. This provides a higher level of security that cannot be achieved by `msal-node` alone. This feature is currently only supported on Windows.
2319

2420
## Prerequisites
2521

@@ -48,7 +44,7 @@ const pca = new PublicClientApplication(msalConfig);
4844

4945
Please note that `msal-node` will _not_ fallback to the non-brokered flow in the event of a failure. In order to avoid unexpected failures in the future, only enable the broker flow in environments which support it (refer to the [Supported Environment](#supported-environment) section above).
5046

51-
A working sample can be found [here](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/auth-code-cli-brokered-app)
47+
A working sample can be found in the [auth-code-cli-brokered-app sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/auth-code-cli-brokered-app)
5248

5349
## Window Parenting
5450

msal-javascript-conceptual/node/caching.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ ms.reviewer: dmwendia, cwerner, owenrichards, kengaderdus
1717

1818
When MSAL Node acquires a token, it caches it in memory for future usage. MSAL Node manages the token lifetime and refreshing for you. APIs like `acquireTokenSilent()` retrieves access tokens from the cache for a given account:
1919

20-
> :information_source: MSAL does not expose refresh tokens for security reasons. See [FAQ: How do I get the Refresh Token](./faq.md#how-do-i-get-the-refresh-token) for more.
20+
MSAL does not expose refresh tokens for security reasons. Refer to the [FAQ](./faq.md#how-do-i-get-the-refresh-token) for how to get the refresh tokens.
2121

22-
### Using secrets securely
22+
## Use client secrets securely
2323

24-
Secrets should never be hardcoded. The dotenv npm package can be used to store secrets in a .env file (located in project's root directory) that should be included in .gitignore to prevent accidental uploads of the secrets.
24+
Client secrets should never be hardcoded. The dotenv npm package can be used to store secrets in a *.env* file (located in project's root directory) that should be included in *.gitignore* to prevent accidental uploads of the secrets.
2525

2626
```javascript
2727
const msal = require('@azure/msal-node');
@@ -39,7 +39,6 @@ const cca = new msal.ConfidentialClientApplication({
3939
/**
4040
* acquireToken* APIs return an account object containing the "homeAccountId"
4141
* you should keep a record of this in your app and use it later on when calling acquireTokenSilent
42-
* For more, see: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/accounts.md
4342
*/
4443
const someUserHomeAccountId = "Enter_User_Home_Account_Id";
4544

@@ -58,10 +57,10 @@ cca.acquireTokenSilent(silentTokenRequest).then((response) => {
5857
});
5958
```
6059

61-
In production, you would most likely want to serialize and persist the token cache. Depending on the type of application, you can:
60+
In production, you'd most likely want to serialize and persist the token cache. Depending on the type of application, you can:
6261

6362
* Desktop apps, console apps (public clients apps (PCA)):
64-
* Use [MSAL Node Extensions](../../../extensions/msal-node-extensions/README.md), which provides persistence and encryption at rest solutions on Windows, Linux and Mac OS
63+
* Use [MSAL Node Extensions](./extensions.md), which provides persistence and encryption at rest solutions on Windows, Linux and Mac OS
6564
* Web apps, web APIs, daemon apps (confidential client apps (CCA)):
6665
* MSAL's in-memory token cache does not scale for production. Use the [distributed token caching](#performance-and-security) pattern to persist the cache in your choice of storage environment (Redis, MongoDB, SQL databases etc. -keep in mind that you can use these in tandem *e.g.* a Redis-like memory cache as a first layer of persistence, and a SQL database as a second, more stable persistence layer)
6766

@@ -71,7 +70,7 @@ MSAL maintains an in-memory cache. The in-memory cache is representative of the
7170

7271
Note that the in-memory cache is not scalable for server-side applications and performance will degrade after holding a few 100 tokens in cache. For web app and web API scenarios, this approximates to serving a few 100 users. For daemon app scenarios using client credentials grant to call other apps, this means a few 100 tenants. See [performance](#performance-and-security) below for more.
7372

74-
> :warning: We recommend **persisting** the cache with **encryption** for all production applications both for security and desired cache longevity. If you choose not to persist the cache, the [TokenCache](https://azuread.github.io/microsoft-authentication-library-for-js/ref/classes/_azure_msal_node.tokencache.html) interface is still available to access the cached entities.
73+
> :warning: We recommend **persisting** the cache with **encryption** for all production applications both for security and desired cache longevity. If you choose not to persist the cache, the [TokenCache](/javascript/api/@azure/msal-node/tokencache) interface is still available to access the cached entities.
7574
7675
## Persistent cache
7776

@@ -112,10 +111,10 @@ class MyCachePlugin implements ICachePlugin {
112111
}
113112
```
114113

115-
* If you are developing a public client app, [MSAL Node Extensions](../../../extensions/msal-node-extensions/README.md) handles this for you.
114+
* If you are developing a public client app, [MSAL Node Extensions](./extensions.md) handles this for you.
116115
* If you are developing a confidential client app, you should persist the cache via a separate service, since a single, *per-server* cache instance isn't suitable for a cloud environment with many servers and app instances.
117116

118-
> :warning: We strongly recommend to encrypt the token cache when persisting it on disk. For public client apps, this is offered out-of-box with [MSAL Node Extensions](../../../extensions/msal-node-extensions/README.md). For confidential clients however, you are responsible for devising an appropriate encryption solution.
117+
We strongly recommend to encrypt the token cache when persisting it on disk. For public client apps, this is offered out-of-box with [MSAL Node Extensions](../../../extensions/msal-node-extensions/README.md). For confidential clients however, you are responsible for devising an appropriate encryption solution.
119118

120119
## Performance and security
121120

@@ -131,19 +130,19 @@ On confidential client apps that handle users (web apps that sign in users and c
131130
132131
### Web apps
133132

134-
Since web apps are user-facing and often rely on sessions to keep track of each user, the appropriate partition key for caching is often stored within the session data, and needs to be retrieved before the cache lookup can take place. To help with this, MSAL Node provides the [DistributedCachePlugin](https://azuread.github.io/microsoft-authentication-library-for-js/ref/classes/_azure_msal_node.distributedcacheplugin.html) class, which implements the [ICachePlugin](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_common.icacheplugin.html). An instance of `DistributedCachePlugin` requires:
133+
Since web apps are user-facing and often rely on sessions to keep track of each user, the appropriate partition key for caching is often stored within the session data, and needs to be retrieved before the cache lookup can take place. To help with this, MSAL Node provides the [DistributedCachePlugin](/javascript/api/@azure/msal-node/distributedcacheplugin) class, which implements the [ICachePlugin](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_common.icacheplugin.html). An instance of `DistributedCachePlugin` requires:
135134

136-
* a **client interface** ([ICacheClient](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_node.icacheclient.html)), which implements `get` and `set` operations on the persistence server (Redis, MySQL etc.).
137-
* a **partition manager** ([IPartitionManager](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_node.ipartitionmanager.html)), for reading from and writing to cache with respect to a given **session ID**.
135+
* a **client interface** ([ICacheClient](/javascript/api/@azure/msal-node/icacheclient)), which implements `get` and `set` operations on the persistence server (Redis, MySQL etc.).
136+
* a **partition manager** ([IPartitionManager](/javascript/api/@azure/msal-node/ipartitionmanager)), for reading from and writing to cache with respect to a given **session ID**.
138137

139-
Please refer to the [Web app using DistributedCachePlugin](../../../samples/msal-node-samples/auth-code-distributed-cache/README.md) for a sample implementation.
138+
Please refer to the [Web app using DistributedCachePlugin](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/auth-code-distributed-cache) for a sample implementation.
140139

141-
## More information
140+
## See also
142141

143142
See the samples below for more about how to handle caching in MSAL Node apps:
144143

145-
* [(PCA) Console app using MSAL Node Extensions](../../../extensions/samples/msal-node-extensions/index.js)
146-
* [(PCA) Dektop app using MSAL Node Extensions](../../../extensions/samples/electron-webpack/README.md)
147-
* [(CCA) Web app using DistributedCachePlugin](../../../samples/msal-node-samples/auth-code-distributed-cache/README.md)
148-
* [(CCA) Web API using a custom distributed cache plugin](../../../samples/msal-node-samples/auth-code-distributed-cache/README.md)
149-
* [(CCA) Daemon app using a custom distributed cache plugin](../../../samples/msal-node-samples/auth-code-distributed-cache/README.md)
144+
* [(PCA) Console app using MSAL Node Extensions](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/extensions/samples/msal-node-extensions/index.js)
145+
* [(PCA) Dektop app using MSAL Node Extensions](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/extensions/samples/electron-webpack)
146+
* [(CCA) Web app using DistributedCachePlugin](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/auth-code-distributed-cache)
147+
- [Microsoft Authentication Extensions for Node](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/master/extensions/msal-node-extensions)
148+
- [Microsoft Authentication Library for Node](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/master/lib/msal-node)

0 commit comments

Comments
 (0)