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: articles/active-directory/develop/scenario-spa-acquire-token.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ ms.service: active-directory
9
9
ms.subservice: develop
10
10
ms.topic: conceptual
11
11
ms.workload: identity
12
-
ms.date: 06/10/2022
12
+
ms.date: 05/18/2023
13
13
ms.author: henrymbugua
14
14
s.reviewer: negoe
15
15
ms.custom: aaddev
@@ -18,7 +18,7 @@ ms.custom: aaddev
18
18
19
19
# Single-page application: Acquire a token to call an API
20
20
21
-
The pattern for acquiring tokens for APIs with [MSAL.js](https://github.com/AzureAD/microsoft-authentication-library-for-js) is to first attempt a silent token request by using the `acquireTokenSilent` method. When this method is called, the library first checks the cache in browser storage to see if a non-expired access token exists and returns it. If no access token is found or the access token found has expired, it attempts to use its refresh token to get a fresh access token. If the refresh token's 24-hour lifetime has also expired, MSAL.js will open a hidden iframe to silently request a new authorization code by leveraging the existing active session with Azure AD (if any), which will then be exchanged for a fresh set of tokens (access _and_ refresh tokens). For more information about single sign-on (SSO) session and token lifetime values in Azure AD, see [Token lifetimes](configurable-token-lifetimes.md). For more information on MSAL.js cache lookup policy, see: [Acquiring an Access Token](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/acquire-token.md#acquiring-an-access-token).
21
+
The pattern for acquiring tokens for APIs with [MSAL.js](https://github.com/AzureAD/microsoft-authentication-library-for-js) is to first attempt a silent token request by using the `acquireTokenSilent` method. When this method is called, the library first checks the cache in browser storage to see if a non-expired access token exists and returns it. If no access token is found or the access token found has expired, it attempts to use its refresh token to get a fresh access token. If the refresh token's 24-hour lifetime has also expired, MSAL.js opens a hidden iframe to silently request a new authorization code by using the existing active session with Azure Active Directory (Azure AD) (if any), which will then be exchanged for a fresh set of tokens (access _and_ refresh tokens). For more information about single sign-on (SSO) session and token lifetime values in Azure AD, see [Token lifetimes](configurable-token-lifetimes.md). For more information on MSAL.js cache lookup policy, see: [Acquiring an Access Token](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/acquire-token.md#acquiring-an-access-token).
22
22
23
23
The silent token requests to Azure AD might fail for reasons like a password change or updated conditional access policies. More often, failures are due to the refresh token's 24-hour lifetime expiring and [the browser blocking third party cookies](reference-third-party-cookies-spas.md), which prevents the use of hidden iframes to continue authenticating the user. In these cases, you should invoke one of the interactive methods (which may prompt the user) to acquire tokens:
24
24
@@ -31,7 +31,7 @@ The choice between a pop-up or redirect experience depends on your application f
31
31
32
32
- If you don't want users to move away from your main application page during authentication, we recommend the pop-up method. Because the authentication redirect happens in a pop-up window, the state of the main application is preserved.
33
33
34
-
- If users have browser constraints or policies where pop-up windows are disabled, you can use the redirect method. Use the redirect method with the Internet Explorer browser, because there are [known issues with pop-up windows on Internet Explorer](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/internet-explorer.md#popups).
34
+
- If users have browser constraints or policies where pop-up windows are disabled, you can use the redirect method. Use the redirect method with the Internet Explorer browser, because there are [known issues with pop-up windows on Internet Explorer](msal-js-known-issues-ie-edge-browsers.md).
35
35
36
36
You can set the API scopes that you want the access token to include when it's building the access token request. All requested scopes might not be granted in the access token. That depends on the user's consent.
37
37
@@ -115,7 +115,7 @@ userAgentApplication
115
115
116
116
The MSAL Angular wrapper provides the HTTP interceptor, which will automatically acquire access tokens silently and attach them to the HTTP requests to APIs.
117
117
118
-
You can specify the scopes for APIs in the `protectedResourceMap` configuration option. `MsalInterceptor`will request the specified scopes when automatically acquiring tokens.
118
+
You can specify the scopes for APIs in the `protectedResourceMap` configuration option. `MsalInterceptor`requests the specified scopes when automatically acquiring tokens.
119
119
120
120
```javascript
121
121
// In app.module.ts
@@ -201,7 +201,7 @@ Alternatively, you can explicitly acquire tokens by using the acquire-token meth
201
201
# [Angular (MSAL.js v1)](#tab/angular1)
202
202
203
203
The MSAL Angular wrapper provides the HTTP interceptor, which will automatically acquire access tokens silently and attach them to the HTTP requests to APIs.
204
-
You can specify the scopes for APIs in the `protectedResourceMap` configuration option. `MsalInterceptor`will request the specified scopes when automatically acquiring tokens.
204
+
You can specify the scopes for APIs in the `protectedResourceMap` configuration option. `MsalInterceptor`requests the specified scopes when automatically acquiring tokens.
205
205
206
206
```javascript
207
207
// app.module.ts
@@ -353,7 +353,7 @@ publicClientApplication
353
353
354
354
# [JavaScript (MSAL.js v2)](#tab/javascript2)
355
355
356
-
The following pattern is as described earlier but shown with a redirect method to acquire tokens interactively. You'll need to call and await `handleRedirectPromise` on page load.
356
+
The following pattern is as described earlier but shown with a redirect method to acquire tokens interactively. You need to call and await `handleRedirectPromise` on page load.
@@ -392,7 +392,7 @@ if (redirectResponse !== null) {
392
392
393
393
# [JavaScript (MSAL.js v1)](#tab/javascript1)
394
394
395
-
The following pattern is as described earlier but shown with a redirect method to acquire tokens interactively. You'll need to register the redirect callback as mentioned earlier.
395
+
The following pattern is as described earlier but shown with a redirect method to acquire tokens interactively. You need to register the redirect callback as mentioned earlier.
396
396
397
397
```javascript
398
398
functionauthCallback(error, response) {
@@ -514,7 +514,7 @@ This code is the same as described earlier.
514
514
515
515
# [React](#tab/react)
516
516
517
-
If `acquireTokenSilent` fails, fallback to `acquireTokenRedirect`. This method will initiate a full-frame redirect and the response will be handled when returning to the application. When this component is rendered after returning from the redirect, `acquireTokenSilent` should now succeed as the tokens will be pulled from the cache.
517
+
If `acquireTokenSilent` fails, fallback to `acquireTokenRedirect`. This method initiates a full-frame redirect and the response will be handled when returning to the application. When this component is rendered after returning from the redirect, `acquireTokenSilent` should now succeed as the tokens will be pulled from the cache.
0 commit comments