Skip to content

Commit d329737

Browse files
committed
application screenshots
1 parent 3306dc7 commit d329737

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed
48.9 KB
Loading
55 KB
Loading
32.6 KB
Loading
38.7 KB
Loading

articles/active-directory/develop/tutorial-v2-javascript-auth-code.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,23 @@ ms.custom: aaddev
1919
> [!IMPORTANT]
2020
> This feature is currently in preview. Previews are made available to you on the condition that you agree to the [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/). Some aspects of this feature might change before general availability (GA).
2121
22-
This tutorial shows you how to create a JavaScript single-page application (SPA) that uses the Microsoft Authentication Library (MSAL) for JavaScript v2.0 (preview) to:
22+
This tutorial shows you how to create a JavaScript single-page application (SPA) that uses the Microsoft Authentication Library (MSAL) for JavaScript v2.0 to:
2323

2424
> [!div class="checklist"]
2525
> * Perform the OAuth 2.0 authorization code flow with PKCE
2626
> * Sign in personal Microsoft accounts as well as work and school accounts
2727
> * Acquire an access token
2828
> * Call Microsoft Graph or your own API that requires access tokens obtained from the Microsoft identity platform endpoint
2929
30-
MSAL.js 2.0 (preview) improves on MSAL.js 1.0 by supporting the authorization code flow in the browser instead of using the implicit flow. MSAL.js 2.0 (preview) supports most features available in 1.0, but there are nuances to the authentication flow in both.
30+
MSAL.js 2.0 improves on MSAL.js 1.0 by supporting the authorization code flow in the browser instead of the implicit grant flow. MSAL.js 2.0 does **NOT** support the implicit flow.
3131

32-
MSAL.js 2.0 (preview) does **NOT** support the implicit flow.
33-
34-
## How the sample app generated by this guide works
32+
## How the tutorial app works
3533

3634
![Shows how the sample app generated by this tutorial works](media/active-directory-develop-guidedsetup-javascriptspa-introduction/javascriptspa-intro.svg)
3735

38-
The sample application created by this guide enables a JavaScript SPA to query the Microsoft Graph API or a web API that accepts tokens from the Microsoft identity platform endpoint. In this scenario, after a user signs in, an access token is requested and added to HTTP requests through the authorization header. Token acquisition and renewal are handled by the Microsoft Authentication Library (MSAL).
36+
The application you create in this tutorial enables a JavaScript SPA to query the Microsoft Graph API by acquiring security tokens from the the Microsoft identity platform endpoint. In this scenario, after a user signs in, an access token is requested and added to HTTP requests in the authorization header. Token acquisition and renewal are handled by the Microsoft Authentication Library for JavaScript (MSAL.js).
3937

40-
This guide uses the following library:
38+
This tutorial uses the following library:
4139

4240
| | |
4341
|---|---|
@@ -61,7 +59,9 @@ To continue with the tutorial and build the application yourself, continue on to
6159

6260
## Create your project
6361

64-
Once you have [Node.js](https://nodejs.org/en/download/) installed, create a folder to host your application. Then, implement a small [Express](https://expressjs.com/) web server to serve your *index.html* file.
62+
Once you have [Node.js](https://nodejs.org/en/download/) installed, create a folder to host your application, for example *msal-spa-tutorial*.
63+
64+
Next, implement a small [Express](https://expressjs.com/) web server to serve your *index.html* file.
6565

6666
1. First, change to your project directory in your terminal and then run the following `npm` commands:
6767
```console
@@ -114,9 +114,20 @@ Once you have [Node.js](https://nodejs.org/en/download/) installed, create a fol
114114
console.log(`Listening on port ${port}...`);
115115
```
116116

117-
You now have a small webserver to serve your SPA. The folder structure you should have at the end of this tutorial is similar to the following:
117+
You now have a small webserver to serve your SPA. After completing the rest of the tutorial, the file and folder structure of your project should look similar to the following:
118118

119-
![A text representation of the intended SPA folder structure](./media/tutorial-v2-javascript-spa/single-page-application-folder-structure.png)
119+
```
120+
msal-spa-tutorial/
121+
├── app
122+
│   ├── authConfig.js
123+
│   ├── authPopup.js
124+
│   ├── authRedirect.js
125+
│   ├── graphConfig.js
126+
│   ├── graph.js
127+
│   ├── index.html
128+
│   └── ui.js
129+
└── server.js
130+
```
120131
121132
## Create the SPA UI
122133
@@ -130,7 +141,7 @@ You now have a small webserver to serve your SPA. The folder structure you shoul
130141
<head>
131142
<meta charset="UTF-8">
132143
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
133-
<title>Quickstart | MSAL.JS Vanilla JavaScript SPA</title>
144+
<title>Tutorial | MSAL.js JavaScript SPA</title>
134145
135146
<!-- IE support: add promises polyfill before msal.js -->
136147
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/js/browser/bluebird.min.js"></script>
@@ -142,15 +153,15 @@ You now have a small webserver to serve your SPA. The folder structure you shoul
142153
</head>
143154
<body>
144155
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
145-
<a class="navbar-brand" href="/">MS Identity Platform</a>
156+
<a class="navbar-brand" href="/">Microsoft identity platform</a>
146157
<div class="btn-group ml-auto dropleft">
147158
<button type="button" id="SignIn" class="btn btn-secondary" onclick="signIn()">
148159
Sign In
149160
</button>
150161
</div>
151162
</nav>
152163
<br>
153-
<h5 class="card-header text-center">Vanilla JavaScript SPA calling MS Graph API with MSAL.JS</h5>
164+
<h5 class="card-header text-center">JavaScript SPA calling Microsoft Graph API with MSAL.js</h5>
154165
<br>
155166
<div class="row" style="margin:auto" >
156167
<div id="card-div" class="col-md-3" style="display:none">
@@ -163,7 +174,7 @@ You now have a small webserver to serve your SPA. The folder structure you shoul
163174
<button class="btn btn-primary" id="seeProfile" onclick="seeProfile()">See Profile</button>
164175
<br>
165176
<br>
166-
<button class="btn btn-primary" id="readMail" onclick="readMail()">Read Mails</button>
177+
<button class="btn btn-primary" id="readMail" onclick="readMail()">Read Mail</button>
167178
</div>
168179
</div>
169180
</div>
@@ -547,44 +558,47 @@ In the sample application created in this tutorial, the `callMSGraph()` method i
547558

548559
You've completed creation of the application and are now ready to launch the Node.js web server and test the app's functionality.
549560

550-
1. Start the Node.js web server by running the following commands from within the application folder:
561+
1. Start the Node.js web server by running the following command from within the root of your project folder:
551562

552563
```console
553564
npm start
554565
```
555-
1. In your browser, enter `http://localhost:3000` or `http://localhost:<port>`, where `<port>` is the port that your web server is listening on. You should see the contents of your *index.html* file and the **Sign In** button.
566+
1. In your browser, navigate to `http://localhost:3000` or `http://localhost:<port>`, where `<port>` is the port that your web server is listening on. You should see the contents of your *index.html* file and the **Sign In** button.
556567

557568
### Sign in to the application
558569

559570
After the browser loads your *index.html* file, select **Sign In**. You're prompted to sign in with the Microsoft identity platform endpoint:
560571

561-
![The JavaScript SPA account sign-in window](media/active-directory-develop-guidedsetup-javascriptspa-test/javascriptspascreenshot1.png)
572+
:::image type="content" source="media/tutorial-v2-javascript-spa/spa-01-signin-dialog.png" alt-text="Web browser displaying sign-in dialog":::
562573

563574
### Provide consent for application access
564575

565-
The first time that you sign in to your application, you're prompted to grant it access to your profile and sign you in:
576+
The first time you sign in to your application, you're prompted to grant it access to your profile and sign you in:
566577

567-
![The "Permissions requested" window](media/active-directory-develop-guidedsetup-javascriptspa-test/javascriptspaconsent.png)
578+
:::image type="content" source="media/tutorial-v2-javascript-spa/spa-02-consent-dialog.png" alt-text="Content dialog displayed in web browser":::
568579

569-
### View application results
580+
If you consent to the requested permissions, the web applications displays your user name, signifying a successful login:
570581

571-
After you sign in, your user profile information is returned in the Microsoft Graph API response that's displayed:
582+
:::image type="content" source="media/tutorial-v2-javascript-spa/spa-03-signed-in.png" alt-text="Results of a successful sign-in in the web browser":::
572583

573-
![Results from the Microsoft Graph API call](media/active-directory-develop-guidedsetup-javascriptspa-test/javascriptsparesults.png)
584+
### Call the Graph API
585+
586+
After you sign in, select **See Profile** to view the user profile information returned in the response from the call to the Microsoft Graph API:
587+
588+
:::image type="content" source="media/tutorial-v2-javascript-spa/spa-04-see-profile.png" alt-text="Profile information from Microsoft Graph displayed in the browser":::
574589

575590
### More information about scopes and delegated permissions
576591

577-
The Microsoft Graph API requires the *user.read* scope to read a user's profile. By default, this scope is automatically added in every application that's registered in the Azure portal. Other APIs for Microsoft Graph, as well as custom APIs for your back-end server, might require additional scopes. For example, the Microsoft Graph API requires the *Mail.Read* scope in order to list the user's mails.
592+
The Microsoft Graph API requires the *user.read* scope to read a user's profile. By default, this scope is automatically added in every application that's registered in the Azure portal. Other APIs for Microsoft Graph, as well as custom APIs for your back-end server, might require additional scopes. For example, the Microsoft Graph API requires the *Mail.Read* scope in order to list the user's email.
578593

579-
> [!NOTE]
580-
> The user might be prompted for additional consent as you add scopes.
594+
As you add scopes, your users might be prompted to provide additional consent for the added scopes.
581595

582-
If a back-end API doesn't require a scope (not recommended), you can use *clientId* as the scope in the calls to acquire tokens.
596+
If a back-end API doesn't require a scope, which isn't recommended, you can use `clientId` as the scope in the calls to acquire tokens.
583597

584598
[!INCLUDE [Help and support](../../../includes/active-directory-develop-help-support-include.md)]
585599

586600
## Next steps
587601

588602
To learn more about the auth code flow, as well as the differences between the implicit and authorization code flows, see [Microsoft identity platform and OAuth 2.0 authorization code flow](v2-oauth2-auth-code-flow.md).
589603

590-
If you'd like to dive deeper into JavaScript single-page application development on the Microsoft identity platform, the multi-part [Scenario: Single-page application](scenario-spa-overview.md) series of articles can help you get started.
604+
If you'd like to dive deeper into JavaScript single-page application development on the Microsoft identity platform, the multi-part [Scenario: Single-page application](scenario-spa-overview.md) series of articles can help you get started.

0 commit comments

Comments
 (0)