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-b2c/custom-policies-series-call-rest-api.md
+35-39Lines changed: 35 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,16 +22,16 @@ Azure Active Directory B2C (Azure AD B2C) custom policy allows you to interact w
22
22
23
23
In this article, you'll learn how to:
24
24
25
-
- Create and deploy a sample Node.js app.
25
+
- Create and deploy a sample Node.js app for use as a RESTful service.
26
26
27
-
- Make an HTTP call to the Node.js app by using the RESTful technical profile.
27
+
- Make an HTTP call to the Node.js RESTful service by using the RESTful technical profile.
28
28
29
-
- Handle or report an error that's returned by the Node.js app in your custom policy.
29
+
- Handle or report an error that a RESTful service returns to your custom policy.
30
30
31
31
32
32
## Scenario overview
33
33
34
-
In [Create branching in user journey by using Azure AD B2C custom policies](custom-policies-series-branch-in-user-journey.md), users who select *Personal Account* need to provide a valid invitation access code to proceed. We use a static access code, but real apps don't work this way. If the service, which issues the access codes is external to your custom policy, you must make a call to that service, and pass the access code input by the user for validation. If the access code is valid, the service returns an HTTP 200 (OK) response, and Azure AD B2C issues JWT token. Otherwise, the service returns an HTTP 409 (Conflict) response, and the use must re-enter an access code.
34
+
In [Create branching in user journey by using Azure AD B2C custom policies](custom-policies-series-branch-in-user-journey.md), users who select *Personal Account* need to provide a valid invitation access code to proceed. We use a static access code, but real world apps don't work this way. If the service that issues the access codes is external to your custom policy, you must make a call to that service, and pass the access code input by the user for validation. If the access code is valid, the service returns an HTTP 200 (OK) response, and Azure AD B2C issues JWT token. Otherwise, the service returns an HTTP 409 (Conflict) response, and the use must re-enter an access code.
35
35
36
36
:::image type="content" source="media/custom-policies-series-call-rest-api/screenshot-of-call-rest-api-call.png" alt-text="A flowchart of calling a R E S T A P I.":::
37
37
@@ -95,19 +95,19 @@ You need to deploy an app, which will serve as your external app. Your custom po
95
95
}
96
96
});
97
97
98
-
app.listen(3000, () => {
99
-
console.log(`Access code service listening on port !`+3000);
98
+
app.listen(80, () => {
99
+
console.log(`Access code service listening on port !`+80);
100
100
});
101
101
```
102
102
103
103
You can observe that when a user submits a wrong access code, you can return an error directly from the RESTAPI. Custom policies allow you to return an HTTP4xx error message, such as, 400 (bad request), or 409 (conflict) response status code with a response JSON body formatted as shown in`errorResponse`variable. The source of the accessCode in the app could be read from a database. Learn more about [Returning validation error message](restful-technical-profile.md#returning-validation-error-message).
104
104
105
105
1. To test the app works as expected, use the following steps:
106
-
1. In your terminal, run the `node index.js` command to start your app server on port `3000`.
106
+
1. In your terminal, run the `node index.js` command to start your app server on port `80`.
107
107
1. To make a POST request similar to the one shown below, you can use an HTTP client such as [Microsoft PowerShell](https://learn.microsoft.com/powershell/scripting/overview) or [Postman](https://www.postman.com/):
108
108
109
109
```http
110
-
POST http://localhost:3000/validate-accesscode HTTP/1.1
110
+
POST http://localhost/validate-accesscode HTTP/1.1
111
111
Host: localhost
112
112
Content-Type: application/x-www-form-urlencoded
113
113
@@ -118,7 +118,7 @@ You need to deploy an app, which will serve as your external app. Your custom po
$response=Invoke-RestMethod -Method Post -Uri $endpoint -Body $body
124
124
echo $response
@@ -146,11 +146,11 @@ For your custom policy to reach your Node.js app, it needs to be reachable, so,
146
146
147
147
Follow the steps in [Deploy your app to Azure](../app-service/quickstart-nodejs.md#deploy-to-azure) to deploy your Node.js app to Azure. For the **Name** of the app, use a descriptive name such as `custompolicyapi`. Hence:
148
148
149
-
- App URL looks similar to `https://custompolicyapi.azurewebsites.net:3000`.
149
+
- App URL looks similar to `https://custompolicyapi.azurewebsites.net`.
150
150
151
-
- Service endpoint looks similar to `https://custompolicyapi.azurewebsites.net:3000/validate-accesscode`.
151
+
- Service endpoint looks similar to `https://custompolicyapi.azurewebsites.net/validate-accesscode`.
152
152
153
-
You can test the app you've deployed by using an HTTP client such as [Microsoft PowerShell](https://learn.microsoft.com/powershell/scripting/overview) or [Postman](https://www.postman.com/). This time, use `https://custompolicyapi.azurewebsites.net:3000/validate-accesscode` as the endpoint.
153
+
You can test the app you've deployed by using an HTTP client such as [Microsoft PowerShell](https://learn.microsoft.com/powershell/scripting/overview) or [Postman](https://www.postman.com/). This time, use `https://custompolicyapi.azurewebsites.net/validate-accesscode` as the endpoint.
154
154
155
155
## Step 2- Call the RESTAPI
156
156
@@ -159,32 +159,34 @@ Now that your app is running, you need to make an HTTP call from your custom pol
159
159
160
160
### Step 2.1- Define a RESTful Technical profile
161
161
162
-
In your `ContosoCustomPolicy.XML` file, locate the `ClaimsProviders` section, and define a newRESTfulTechnical Profile by using the following code:
162
+
In your `ContosoCustomPolicy.XML` file, locate the `ClaimsProviders` section, and define a newRESTfultechnical profile by using the following code:
From the protocol, you can observe that we configure the Technical Profile to use the *RestfulProvider*. You can also observe the following information it the metadata section:
186
188
187
-
- The `ServiceUrl` represents the APIendpoint. Its value is `https://custompolicyapi.azurewebsites.net:3000/validate-accesscode`. If you deployed your Node.js app using an alternative method, make sure to update the endpoint value.
189
+
- The `ServiceUrl` represents the APIendpoint. Its value is `https://custompolicyapi.azurewebsites.net/validate-accesscode`. If you deployed your Node.js app using an alternative method, make sure to update the endpoint value.
188
190
189
191
-`SendClaimsIn` specifies how the input claims are sent to the RESTful claims provider. Possible values:`Body (default)`, `Form`, `Header`, `Url` or `QueryString`. When you use `Body`, such as inthis article, you invoke the *POST*HTTP verb, and the data you send to the APIif formatted as key, value pairs in the body of the request. Learn [how to invoke the *GET*HTTP verb, and pass data as query string](restful-technical-profile.md#metadata).
190
192
@@ -308,10 +310,4 @@ Next, learn:
308
310
309
311
- About [RESTful technical profile](restful-technical-profile.md).
310
312
311
-
- How to [Create a user by using Azure ADB2C custom policy](custom-policies-series-store-user.md)
312
-
313
-
314
-
315
-
316
-
317
-
313
+
- How to [Create a user by using Azure ADB2C custom policy](custom-policies-series-store-user.md)
0 commit comments