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
#Customer intent: As an app developer, I want to learn how to get access tokens and refresh tokens by using the Microsoft identity platform so that my JavaScript app can sign in users of personal accounts, work accounts, and school accounts.
17
17
---
18
18
19
-
# Quickstart: Sign in users and get an access token in a JavaScript SPA using the auth code flow with PKCE
19
+
# Quickstart: Sign in users and get an access token in a JavaScript SPA using the auth code flow with PKCE
20
20
21
-
In this quickstart, you download and run a code sample that demonstrates how a JavaScript single-page application (SPA) can sign in users and call Microsoft Graph using the authorization code flow with Proof Key for Code Exchange (PKCE). The code sample demonstrates how to get an access token to call the Microsoft Graph API or any web API.
21
+
In this quickstart, you download and run a code sample that demonstrates how a JavaScript single-page application (SPA) can sign in users and call Microsoft Graph using the authorization code flow with Proof Key for Code Exchange (PKCE). The code sample demonstrates how to get an access token to call the Microsoft Graph API or any web API.
22
22
23
23
See [How the sample works](#how-the-sample-works) for an illustration.
24
24
@@ -81,10 +81,10 @@ This quickstart uses MSAL.js v2 with the authorization code flow. For a similar
81
81
> [!div renderon="docs"]
82
82
> #### Step 3: Configure your JavaScript app
83
83
>
84
-
> In the *app* folder, open the *authConfig.js* file and update the `clientID`, `authority`, and `redirectUri` values in the `msalConfig` object.
84
+
> In the *app* folder, open the *authConfig.js* file, and then update the `clientID`, `authority`, and `redirectUri` values in the `msalConfig` object.
85
85
>
86
86
> ```javascript
87
-
>// Config object to be passed to Msal on creation
87
+
>// Config object to be passed to MSAL on creation
88
88
>constmsalConfig= {
89
89
> auth: {
90
90
> clientId:"Enter_the_Application_Id_Here",
@@ -104,13 +104,13 @@ This quickstart uses MSAL.js v2 with the authorization code flow. For a similar
104
104
105
105
> [!div renderon="docs"]
106
106
>
107
-
> Modify the values in the `msalConfig` section as described here:
107
+
> Modify the values in the `msalConfig` section:
108
108
>
109
109
> - `Enter_the_Application_Id_Here` is the **Application (client) ID** for the application you registered.
110
110
>
111
111
> To find the value of **Application (client) ID**, go to the app registration's **Overview** page in the Azure portal.
112
-
> - `Enter_the_Cloud_Instance_Id_Here` is the instance of the Azure cloud. For the main or global Azure cloud, enter `https://login.microsoftonline.com/`. For **national** clouds (for example, China), see [National clouds](authentication-national-cloud.md).
113
-
>-`Enter_the_Tenant_info_here` is set to one of the following:
112
+
> - `Enter_the_Cloud_Instance_Id_Here` is the Azure cloud instance. For the main or global Azure cloud, enter `https://login.microsoftonline.com/`. For **national** clouds (for example, China), see [National clouds](authentication-national-cloud.md).
113
+
>-`Enter_the_Tenant_info_here` is one of the following:
114
114
>- If your application supports *accounts inthis organizational directory*, replace this value with the **Tenant ID** or **Tenant name**. For example, `contoso.microsoft.com`.
115
115
>
116
116
> To find the value of the **Directory (tenant) ID**, go to the app registration's **Overview** page in the Azure portal.
@@ -130,11 +130,12 @@ This quickstart uses MSAL.js v2 with the authorization code flow. For a similar
130
130
131
131
> [!div class="sxs-lookup" renderon="portal"]
132
132
> #### Step 3: Your app is configured and ready to run
133
+
>
133
134
> We have configured your project with values of your app's properties.
134
135
135
136
> [!div renderon="docs"]
136
137
>
137
-
>Then, still inthe same folder, edit the *graphConfig.js* file and update the `graphMeEndpoint` and `graphMailEndpoint` values in the `apiConfig` object.
138
+
>Next, open the *graphConfig.js* file to update the `graphMeEndpoint` and `graphMailEndpoint` values in the `apiConfig` object.
138
139
>
139
140
>```javascript
140
141
> // Add here the endpoints for MS Graph API services you would like to use.
@@ -151,9 +152,9 @@ This quickstart uses MSAL.js v2 with the authorization code flow. For a similar
151
152
>
152
153
> [!div renderon="docs"]
153
154
>
154
-
>`Enter_the_Graph_Endpoint_Here` is the endpoint that API calls will be made against. For the main (global) Microsoft Graph API service, enter `https://graph.microsoft.com/` (include the trailing forward-slash). For more information about Microsoft Graph on national clouds, see [National cloud deployment](/graph/deployments).
155
+
>`Enter_the_Graph_Endpoint_Here` is the endpoint that API calls are made against. For the main (global) Microsoft Graph API service, enter `https://graph.microsoft.com/` (include the trailing forward-slash). For more information about Microsoft Graph on national clouds, see [National cloud deployment](/graph/deployments).
155
156
>
156
-
>The `graphMeEndpoint` and `graphMailEndpoint` values in the *graphConfig.js* file should be similar to the followingif you're using the main (global) Microsoft Graph API service:
157
+
>If you're using the main (global) Microsoft Graph API service, the `graphMeEndpoint` and `graphMailEndpoint` values in the *graphConfig.js* file should be similar to the following:
@@ -162,26 +163,28 @@ This quickstart uses MSAL.js v2 with the authorization code flow. For a similar
162
163
>
163
164
> #### Step 4: Run the project
164
165
165
-
Run the project with a web server by using Node.js:
166
+
Run the project with a web server by using Node.js.
166
167
167
168
1. To start the server, run the following commands from within the project directory:
169
+
168
170
```console
169
171
npm install
170
172
npm start
171
173
```
172
-
1. Browse to `http://localhost:3000/`.
174
+
175
+
1. Go to `http://localhost:3000/`.
173
176
174
177
1. Select **Sign In** to start the sign-in process and then call the Microsoft Graph API.
175
178
176
-
The first time you sign in, you're prompted to provide your consent to allow the application to access your profile and sign you in. After you're signed in successfully, your user profile information should be displayed on the page.
179
+
The first time you sign in, you're prompted to provide your consent to allow the application to access your profile and sign you in. After you're signed in successfully, your user profile information is displayed on the page.
177
180
178
181
## More information
179
182
180
183
### How the sample works
181
184
182
185

183
186
184
-
### msal.js
187
+
### MSAL.js
185
188
186
189
The MSAL.js library signs in users and requests the tokens that are used to access an API that's protected by Microsoft identity platform. The sample's *index.html* file contains a reference to the library:
0 commit comments