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
Your single-page web application is registered to call the protected web API. A user authenticates with Azure AD B2C to use the single-page application. The single-page app obtains an authorization grant from Azure AD B2C to access the protected web API.
59
+
Your single-page web application has now been granted permissions to the protected web API for the scopes specified. A user authenticates with Azure AD B2C to use the single-page application. The single-page app uses the authorization grant flow to access the protected web API with an access token returned by Azure AD B2C.
60
60
61
61
## Configure the sample
62
62
63
-
Now that the web API is registered and you have scopes defined, you configure the web API code to use your Azure AD B2C tenant. In this tutorial, you configure a sample Node.js web API you download from GitHub.
63
+
Now that the web API is registered and you've defined scopes, configure the web API code to work with your Azure AD B2C tenant. In this tutorial, you configure a sample Node.js web API you download from GitHub.
64
64
65
-
[Download a \*.zip archive](https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi/archive/master.zip) or clone the sample web API project from GitHub.
65
+
[Download a \*.zip archive](https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi/archive/master.zip) or clone the sample web API project from GitHub. You can also browse directly to the [Azure-Samples/active-directory-b2c-javascript-nodejs-webapi](https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi) project on GitHub.
1. Open the **index.js** file in Visual Studio Code.
74
-
1. Modify the file to reflect your tenant name, the application ID of the web API application, the name of your sign-up/sign-in policy, and the scopes you defined earlier. The block should look similar to the following example (with appropriate `tenantIdGuid` and `clientId` values):
73
+
1. Open the *config.js* file in your code editor.
74
+
1. Modify the variable values to reflect those of the application registration you created earlier. Also update the `policyName` with the user flow you created as part of the prerequisites. For example, *B2C_1_signupsignin1*.
75
75
76
76
```javascript
77
-
var clientID ="<your-webapi-application-ID>";
78
-
var b2cDomainHost ="fabrikamb2c.b2clogin.com";
79
-
vartenantIdGuid="<your-webapi-tenant-ID>";
77
+
var clientID ="<your-webapi-application-ID>";// Application (client) ID
78
+
var b2cDomainHost ="<your-tenant-name>.b2clogin.com";
79
+
vartenantId="<your-tenant-ID>.onmicrosoft.com";
80
80
var policyName ="B2C_1_signupsignin1";
81
81
```
82
82
83
83
#### Enable CORS
84
84
85
-
To allow your single-page application to call the Node.js web API, you need to enable [CORS](https://expressjs.com/en/resources/middleware/cors.html) in the web API. In a real application you should be careful about which domain is making the request, but for this example we will allow requests coming from any domain. To do so, use the following middleware:
85
+
To allow your single-page application to call the Node.js web API, you need to enable [CORS](https://expressjs.com/en/resources/middleware/cors.html) in the web API. In a production application you should be careful about which domain is making the request, but for this tutorial, allow requests from any domain.
The single-page application (SPA) from the [previous tutorial](tutorial-single-page-app.md) in the series uses Azure ADB2Cfor user sign-up and sign-in, and calls the Node.js web APIprotected by the *frabrikamb2c* demo tenant.
98
100
99
-
In this section, you update the single-page application to call the Node.js web APIprotected by *your* Azure ADB2C tenant and which you run on your local machine.
101
+
In this section, you update the single-page application to call the Node.js web APIprotected by *your* Azure ADB2Ctenant(and which you run on your local machine).
100
102
101
103
To change the settings in the SPA:
102
104
@@ -105,11 +107,11 @@ To change the settings in the SPA:
105
107
1. In the `apiConfig` definition, replace the `b2cScopes` value with the full URIfor the scope (the **SCOPE** value you recorded earlier).
106
108
1. Change the `webApi` value to the redirect URI you added when you registered the web API application in an earlier step.
107
109
108
-
The `apiConfig` definition should look similar to the following code block (with your tenant name in the place of`<your-tenant-name>`):
110
+
The `apiConfig` definition should look similar to the following code block, but with your B2Ctenant's name in the place of `<your-tenant-name>`:
cd active-directory-b2c-javascript-msal-singlepageapp
153
+
```
151
154
152
155
1. Run the following commands:
153
156
@@ -164,22 +167,22 @@ Although both applications run locally in this tutorial, they use Azure AD B2C f
164
167
165
168
1. Navigate to `http://localhost:6420` in your browser to view the application.
166
169
1. Sign in using the email address and password you used in the [previous tutorial](tutorial-single-page-app.md). Upon successful login, you should see the `User 'Your Username' logged-in` message.
167
-
1. Select the **Call Web API**button. TheSPA obtains an authorization grant from Azure ADB2C, then accesses the protected web API to display the contentsofits index page:
170
+
1. Select the **Call API** button. The SPA obtains an authorization grant from Azure AD B2C, then accesses the protected web API to display the name of the logged-in user:
168
171
169
172
```Output
170
-
Web APi returned:
171
-
"<html>\r\n<head>\r\n <title>Azure AD B2C API Sample</title>\r\n ...
173
+
Web API returned:
174
+
{"name":"Lisa Andrews"}
172
175
```
173
176
174
177
## Next steps
175
178
176
-
In this tutorial, you learned how to:
179
+
In this tutorial, you:
177
180
178
181
> [!div class="checklist"]
179
-
>*Add a web API application
180
-
>*Configure scopes fora web API
181
-
>*Grant permissions to the web API
182
-
>*Configure the sample to use the application
182
+
> * Created a web API application registration in your Azure AD B2C tenant
183
+
> * Configured scopes for the web API
184
+
> * Granted permissions to the web API
185
+
> * Modified a web API code sample to work with your tenant
183
186
184
187
Now that you've seen an SPA request a resource from a protected web API, gain a deeper understanding of how these application types interact with each other and with Azure ADB2C.
Copy file name to clipboardExpand all lines: includes/active-directory-b2c-permissions-api.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ author: msmimart
3
3
ms.service: active-directory-b2c
4
4
ms.subservice: B2C
5
5
ms.topic: include
6
-
ms.date: 10/16/2019
6
+
ms.date: 03/23/2019
7
7
ms.author: mimart
8
8
# Used by the web app/web API tutorials for granting a web application access to
9
9
# a registered web API application
@@ -24,8 +24,8 @@ ms.author: mimart
24
24
1. Select the **My APIs** tab.
25
25
1. Select the API to which the web application should be granted access. For example, *webapi1*.
26
26
1. Under **Permission**, expand **demo**, and then select the scopes that you defined earlier. For example, *demo.read* and *demo.write*.
27
-
1. Select **Add permissions**. As directed, wait a few minutes before proceeding to the next step.
27
+
1. Select **Add permissions**.
28
28
1. Select **Grant admin consent for (your tenant name)**.
29
-
1.Select your currently signed-in administrator account, or sign in with an account in your Azure AD B2C tenant that's been assigned at least the *Cloud application administrator* role.
29
+
1.If you're prompted to select an account, select your currently signed-in administrator account, or sign in with an account in your Azure AD B2C tenant that's been assigned at least the *Cloud application administrator* role.
30
30
1. Select **Accept**.
31
-
1. Select **Refresh**, and then verify that "Granted for ..." appears under **Status** for both scopes. It might take a few minutes for the permissions to propagate.
31
+
1. Select **Refresh**, and then verify that "Granted for ..." appears under **Status** for both scopes.
0 commit comments