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
+33-34Lines changed: 33 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Single-page application (acquire a token to call an API) - Microsoft identity platform
3
-
description: Learn how to build a single-page application (Acquire a token to call an API)
3
+
description: Learn how to build a single-page application (acquire a token to call an API)
4
4
services: active-directory
5
5
documentationcenter: dev-center-name
6
6
author: negoe
@@ -15,34 +15,34 @@ ms.workload: identity
15
15
ms.date: 08/20/2019
16
16
ms.author: negoe
17
17
ms.custom: aaddev
18
-
#Customer intent: As an application developer, I want to know how to write a single-page application using the Microsoft identity platform for developers.
18
+
#Customer intent: As an application developer, I want to know how to write a single-page application by using the Microsoft identity platform for developers.
19
19
ms.collection: M365-identity-device-management
20
20
---
21
21
22
-
# Single-page application - acquire a token to call an API
22
+
# Single-page application: Acquire a token to call an API
23
23
24
-
The pattern for acquiring tokens for APIs with MSAL.js is to first attempt a silent token request using the `acquireTokenSilent` method. When this method is called, the library first checks the cache in the browser storage to see if a valid token exists and returns it. When there is no valid token in the cache, it sends a silent token request to Azure Active Directory (Azure AD) from a hidden iframe. This method also allows the library to renew tokens. For more information about single sign-on session and token lifetime values in Azure AD, see [token lifetimes](active-directory-configurable-token-lifetimes.md).
24
+
The pattern for acquiring tokens for APIs with MSAL.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 valid token exists and returns it. When no valid token is in the cache, it sends a silent token request to Azure Active Directory (Azure AD) from a hidden iframe. This method also allows the library to renew tokens. For more information about single sign-on session and token lifetime values in Azure AD, see [Token lifetimes](active-directory-configurable-token-lifetimes.md).
25
25
26
-
The silent token requests to Azure AD may fail for some reasons such as an expired Azure AD session or a password change. In that case, you can invoke one of the interactive methods(which will prompt the user) to acquire tokens.
26
+
The silent token requests to Azure AD might fail for reasons like an expired Azure AD session or a password change. In that case, you can invoke one of the interactive methods(which will prompt the user) to acquire tokens:
27
27
28
-
*[Acquire token with a pop-up window](#acquire-token-with-a-pop-up-window) using `acquireTokenPopup`
29
-
*[Acquire token with redirect](#acquire-token-with-redirect) using `acquireTokenRedirect`
28
+
*[Pop-up window](#acquire-a-token-with-a-pop-up-window), by using `acquireTokenPopup`
29
+
*[Redirect](#acquire-a-token-with-a-redirect), by using `acquireTokenRedirect`
30
30
31
-
**Choosing between a pop-up or redirect experience**
31
+
## Choose between a pop-up or redirect experience
32
32
33
-
You cannot use a combination of both the pop-up and redirect methods in your application. The choice between a pop-up or redirect experience depends on your application flow.
33
+
You can't use both the pop-up and redirect methods in your application. The choice between a pop-up or redirect experience depends on your application flow:
34
34
35
-
* If you don't want the user to navigate away from your main application page during authentication, it's recommended to use the pop-up methods. Since the authentication redirect happens in a pop-up window, the state of the main application is preserved.
35
+
* If you don't want users to move away from your main application page during authentication, we recommended the pop-up method. Because the authentication redirect happens in a pop-up window, the state of the main application is preserved.
36
36
37
-
*There are certain cases where you may need to use the redirect methods. If users of your application have browser constraints or policies where pop-ups windows are disabled, you can use the redirect methods. It's also recommended to use the redirect methods with Internet Explorer browser since there are certain [known issues with Internet Explorer](https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/Known-issues-on-IE-and-Edge-Browser) when handling pop-up windows.
37
+
* If users have browser constraints or policies where pop-ups 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/wiki/Known-issues-on-IE-and-Edge-Browser).
38
38
39
-
You can set the API scopes that you want the access token to include when building the access token request. Note, that all requested scopes may not be granted in the access token and depends on the user's consent.
39
+
You can set the API scopes that you want the access token to include when it's building the access token request. Note that all requested scopes might not be granted in the access token. That depends on the user's consent.
40
40
41
-
## Acquire token with a pop-up window
41
+
## Acquire a token with a pop-up window
42
42
43
43
### JavaScript
44
44
45
-
The above pattern using the methods for a pop-up experience:
45
+
The following code combines the previously described pattern with the methods for a pop-up experience:
The MSAL Angular wrapper provides the convenience of adding the HTTP interceptor, which will automatically acquire access tokens silently and attach them to the HTTP requests to APIs.
72
+
The MSAL Angular wrapper provides the HTTP interceptor, which will automatically acquire access tokens silently and attach them to the HTTP requests to APIs.
73
73
74
-
You can specify the scopes for APIs in the `protectedResourceMap`config option, which the MsalInterceptor will request when automatically acquiring tokens.
74
+
You can specify the scopes for APIs in the `protectedResourceMap`configuration option. `MsalInterceptor` will request these scopes when automatically acquiring tokens.
75
75
76
76
```javascript
77
77
//In app.module.ts
@@ -90,7 +90,7 @@ providers: [ ProductService, {
90
90
],
91
91
```
92
92
93
-
For success and failure of the silent token acquisition, MSAL Angular provides callbacks you can subscribe to. It's also important to remember to unsubscribe.
93
+
For success and failure of the silent token acquisition, MSAL Angular provides callbacks that you can subscribe to. It's also important to remember to unsubscribe.
94
94
95
95
```javascript
96
96
// In app.component.ts
@@ -107,17 +107,17 @@ ngOnDestroy() {
107
107
}
108
108
```
109
109
110
-
Alternatively, you can also explicitly acquire tokens using the acquiretoken methods as described in the core MSAL.js library.
110
+
Alternatively, you can explicitly acquire tokens by using the acquire-token methods as described in the core MSAL.js library.
111
111
112
-
## Acquire token with redirect
112
+
## Acquire a token with a redirect
113
113
114
114
### JavaScript
115
115
116
-
The pattern is as described above but shown with a redirect method to acquire token interactively. You will need to register the redirect callback as mentioned above.
116
+
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.
You can request optional claims in your app to specify which additional claims to include in tokens for your application. In order to request optional claims in the id_token, you can send a stringified claims object to the claimsRequest field of the AuthenticationParameters.ts class.
142
+
## Request optional claims
143
+
You can use optional claims for the following purposes:
144
144
145
-
You can use optional claims for following purpose:
146
-
147
-
- To include additional claims in tokens for your application.
145
+
- Include additional claims in tokens for your application.
148
146
- Change the behavior of certain claims that Azure AD returns in tokens.
149
-
- Add and access custom claims for your application.
147
+
- Add and access custom claims for your application.
150
148
149
+
To request optional claims in `IdToken`, you can send a stringified claims object to the `claimsRequest` field of the `AuthenticationParameters.ts` class.
151
150
152
151
### JavaScript
153
152
```javascript
@@ -167,14 +166,14 @@ var request = {
167
166
168
167
myMSALObj.acquireTokenPopup(request);
169
168
```
170
-
To learn more about optional claims, checkout [optional claims](active-directory-optional-claims.md)
169
+
To learn more, see [Optional claims](active-directory-optional-claims.md).
Copy file name to clipboardExpand all lines: articles/active-directory/develop/scenario-spa-app-configuration.md
+9-11Lines changed: 9 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Single-page application (app's code configuration) - Microsoft identity platform
3
-
description: Learn how to build a single-page application (App's code configuration)
3
+
description: Learn how to build a single-page application (app's code configuration)
4
4
services: active-directory
5
5
documentationcenter: dev-center-name
6
6
author: navyasric
@@ -15,28 +15,26 @@ ms.workload: identity
15
15
ms.date: 05/07/2019
16
16
ms.author: nacanuma
17
17
ms.custom: aaddev
18
-
#Customer intent: As an application developer, I want to know how to write a single-page application using the Microsoft identity platform for developers.
18
+
#Customer intent: As an application developer, I want to know how to write a single-page application by using the Microsoft identity platform for developers.
19
19
ms.collection: M365-identity-device-management
20
20
---
21
21
22
-
# Single-page application - code configuration
22
+
# Single-page application: Code configuration
23
23
24
24
Learn how to configure the code for your single-page application (SPA).
25
25
26
-
## MSAL libraries supporting implicit flow
26
+
## MSAL libraries that support implicit flow
27
27
28
-
Microsoft identity platform provides MSAL.js library to support the implicit flow using the industry recommended secure practices.
29
-
30
-
The libraries supporting implicit flow are:
28
+
The Microsoft identity platform provides the following Microsoft Authentication Library (MSAL) libraries to support implicit flow by using industry-recommended security practices:
31
29
32
30
| MSAL library | Description |
33
31
|--------------|--------------|
34
-
| <br/> [MSAL.js](https://github.com/AzureAD/microsoft-authentication-library-for-js)| Plain JavaScript library for use in any clientside web app built using JavaScript or SPA frameworks such as Angular, Vue.js, React.js, etc. |
35
-
| <br/> [MSAL Angular](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/README.md)| Wrapper of the core MSAL.js library to simplify use in singlepage apps built with the Angular framework. This library is in preview and has [known issues](https://github.com/AzureAD/microsoft-authentication-library-for-js/issues?q=is%3Aopen+is%3Aissue+label%3Aangular) with certain Angular versions and browsers. |
32
+
| <br/> [MSAL.js](https://github.com/AzureAD/microsoft-authentication-library-for-js)| Plain JavaScript library for use in any client-side web app that's built through JavaScript or SPA frameworks such as Angular, Vue.js, and React.js. |
33
+
| <br/> [MSAL Angular](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/README.md)| Wrapper of the core MSAL.js library to simplify use in single-page apps that are built through the Angular framework. This library is in preview and has [known issues](https://github.com/AzureAD/microsoft-authentication-library-for-js/issues?q=is%3Aopen+is%3Aissue+label%3Aangular) with certain Angular versions and browsers. |
36
34
37
35
## Application code configuration
38
36
39
-
In MSAL library, the application registration information is passed as configuration during the library initialization.
37
+
In an MSAL library, the application registration information is passed as configuration during the library initialization.
Copy file name to clipboardExpand all lines: articles/active-directory/develop/scenario-spa-app-registration.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Single-page application (app registration) - Microsoft identity platform
3
-
description: Learn how to build a single-page application (App registration)
3
+
description: Learn how to build a single-page application (app registration)
4
4
services: active-directory
5
5
documentationcenter: dev-center-name
6
6
author: navyasric
@@ -15,33 +15,33 @@ ms.workload: identity
15
15
ms.date: 05/07/2019
16
16
ms.author: nacanuma
17
17
ms.custom: aaddev
18
-
#Customer intent: As an application developer, I want to know how to write a single-page application using the Microsoft identity platform for developers.
18
+
#Customer intent: As an application developer, I want to know how to write a single-page application by using the Microsoft identity platform for developers.
19
19
ms.collection: M365-identity-device-management
20
20
---
21
21
22
-
# Single-page application - app registration
22
+
# Single-page application: App registration
23
23
24
24
This page explains the app registration specifics for a single-page application (SPA).
25
25
26
-
Follow the steps to [register a new application with Microsoft identity platform](quickstart-register-app.md), and select the supported accounts for your application. The SPA scenario can support authentication with accounts in your organization or any organization and personal Microsoft accounts.
26
+
Follow the steps to [register a new application with the Microsoft identity platform](quickstart-register-app.md), and select the supported accounts for your application. The SPA scenario can support authentication with accounts in your organization or any organization and personal Microsoft accounts.
27
27
28
28
Next, learn the specific aspects of application registration that apply to single-page applications.
29
29
30
30
## Register a redirect URI
31
31
32
-
The implicit flow sends the tokens in a redirect to the single-page application running in a web browser. Therefore, it's an important requirement to register a redirect URI where your application can receive the tokens. Please ensure that the redirect URI matches exactly with the URI for your application.
32
+
The implicit flow sends the tokens in a redirect to the single-page application running on a web browser. So it's important to register a redirect URI where your application can receive the tokens. Ensure that the redirect URI exactly matches the URI for your application.
33
33
34
-
In the [Azure portal](https://go.microsoft.com/fwlink/?linkid=2083908), navigate to your registered application, on the **Authentication** page of the application, select the **Web** platform and enter the value of the redirect URI for your application in the **Redirect URI** field.
34
+
In the [Azure portal](https://go.microsoft.com/fwlink/?linkid=2083908), go to your registered application. On the **Authentication** page of the application, select the **Web** platform. Enter the value of the redirect URI for your application in the **Redirect URI** field.
35
35
36
36
## Enable the implicit flow
37
37
38
-
On the same **Authentication** page, under **Advanced settings**, you must also enable the **Implicit grant**. If your application is only performing sign in of users and getting ID tokens, it's sufficient to enable **ID tokens**checkbox.
38
+
On the same **Authentication** page, under **Advanced settings**, you must also enable **Implicit grant**. If your application is only signing in users and getting ID tokens, it's enough to select the **ID tokens**check box.
39
39
40
-
If your application also needs to get access tokens to call APIs, make sure to enable the **Access tokens**checkbox as well. For more information, see [ID tokens](./id-tokens.md) and [Access tokens](./access-tokens.md).
40
+
If your application also needs to get access tokens to call APIs, make sure to select the **Access tokens**check box as well. For more information, see [ID tokens](./id-tokens.md) and [Access tokens](./access-tokens.md).
41
41
42
42
## API permissions
43
43
44
-
Single-page applications can call APIs on behalf of the signed-in user. They need to request delegated permissions. For details, see [Add permissions to access web APIs](quickstart-configure-app-access-web-apis.md#add-permissions-to-access-web-apis)
44
+
Single-page applications can call APIs on behalf of the signed-in user. They need to request delegated permissions. For details, see [Add permissions to access web APIs](quickstart-configure-app-access-web-apis.md#add-permissions-to-access-web-apis).
0 commit comments