Skip to content

Commit a9965f4

Browse files
committed
make http call update diagram and TOC
1 parent 6b35941 commit a9965f4

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

articles/active-directory-b2c/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@
485485
href: custom-policies-series-branch-in-user-journey.md
486486
- name: 6 - Validate custom policy files
487487
href: custom-policies-series-install-xml-extensions.md
488-
- name: 7 - Make HTTP call custom policy
488+
- name: 7 - Make HTTP call from custom policy
489489
href: custom-policies-series-call-rest-api.md
490490
displayName: call rest api, http call, http request
491491
- name: 8 - Create user record custom policy

articles/active-directory-b2c/custom-policies-series-call-rest-api.md

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ Azure Active Directory B2C (Azure AD B2C) custom policy allows you to interact w
2222

2323
In this article, you'll learn how to:
2424

25-
- Create and deploy a sample Node.js app.
25+
- Create and deploy a sample Node.js app for use as a RESTful service.
2626

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.
2828

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.
3030

3131

3232
## Scenario overview
3333

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.
3535

3636
:::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.":::
3737

@@ -95,19 +95,19 @@ You need to deploy an app, which will serve as your external app. Your custom po
9595
}
9696
});
9797

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);
100100
});
101101
```
102102

103103
You can observe that when a user submits a wrong access code, you can return an error directly from the REST API. Custom policies allow you to return an HTTP 4xx 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).
104104

105105
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`.
107107
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/):
108108

109109
```http
110-
POST http://localhost:3000/validate-accesscode HTTP/1.1
110+
POST http://localhost/validate-accesscode HTTP/1.1
111111
Host: localhost
112112
Content-Type: application/x-www-form-urlencoded
113113
@@ -118,7 +118,7 @@ You need to deploy an app, which will serve as your external app. Your custom po
118118
119119
```powershell
120120
$accessCode="54321"
121-
$endpoint="http://localhost:3000/validate-accesscode"
121+
$endpoint="http://localhost/validate-accesscode"
122122
$body=$accessCode
123123
$response=Invoke-RestMethod -Method Post -Uri $endpoint -Body $body
124124
echo $response
@@ -146,11 +146,11 @@ For your custom policy to reach your Node.js app, it needs to be reachable, so,
146146
147147
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:
148148
149-
- App URL looks similar to `https://custompolicyapi.azurewebsites.net:3000`.
149+
- App URL looks similar to `https://custompolicyapi.azurewebsites.net`.
150150
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`.
152152
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.
154154

155155
## Step 2 - Call the REST API
156156

@@ -159,32 +159,34 @@ Now that your app is running, you need to make an HTTP call from your custom pol
159159

160160
### Step 2.1 - Define a RESTful Technical profile
161161

162-
In your `ContosoCustomPolicy.XML` file, locate the `ClaimsProviders` section, and define a new RESTful Technical Profile by using the following code:
162+
In your `ContosoCustomPolicy.XML` file, locate the `ClaimsProviders` section, and define a new RESTful technical profile by using the following code:
163163

164164
```xml
165-
<ClaimsProvider>
166-
<DisplayName>HTTP Request Technical Profiles</DisplayName>
167-
<TechnicalProfiles>
168-
<TechnicalProfile Id="ValidateAccessCodeViaHttp">
169-
<DisplayName>Check that the user has entered a valid access code by using Claims Transformations</DisplayName>
170-
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
171-
<Metadata>
172-
<Item Key="ServiceUrl">https://custompolicyapi.azurewebsites.net:3000/validate-accesscode</Item>
173-
<Item Key="SendClaimsIn">Body</Item>
174-
<Item Key="AuthenticationType">None</Item>
175-
<Item Key="AllowInsecureAuthInProduction">true</Item>
176-
</Metadata>
177-
<InputClaims>
178-
<InputClaim ClaimTypeReferenceId="accessCode" PartnerClaimType="accessCode" />
179-
</InputClaims>
180-
</TechnicalProfile>
181-
</TechnicalProfiles>
182-
</ClaimsProvider>
165+
<!--<ClaimsProviders>-->
166+
<ClaimsProvider>
167+
<DisplayName>HTTP Request Technical Profiles</DisplayName>
168+
<TechnicalProfiles>
169+
<TechnicalProfile Id="ValidateAccessCodeViaHttp">
170+
<DisplayName>Check that the user has entered a valid access code by using Claims Transformations</DisplayName>
171+
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
172+
<Metadata>
173+
<Item Key="ServiceUrl">https://custompolicyapi.azurewebsites.net/validate-accesscode</Item>
174+
<Item Key="SendClaimsIn">Body</Item>
175+
<Item Key="AuthenticationType">None</Item>
176+
<Item Key="AllowInsecureAuthInProduction">true</Item>
177+
</Metadata>
178+
<InputClaims>
179+
<InputClaim ClaimTypeReferenceId="accessCode" PartnerClaimType="accessCode" />
180+
</InputClaims>
181+
</TechnicalProfile>
182+
</TechnicalProfiles>
183+
</ClaimsProvider>
184+
<!--</ClaimsProviders>-->
183185
```
184186

185187
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:
186188

187-
- The `ServiceUrl` represents the API endpoint. 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 API endpoint. 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.
188190

189191
- `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 in this article, you invoke the *POST* HTTP verb, and the data you send to the API if 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).
190192

@@ -308,10 +310,4 @@ Next, learn:
308310

309311
- About [RESTful technical profile](restful-technical-profile.md).
310312

311-
- How to [Create a user by using Azure AD B2C custom policy](custom-policies-series-store-user.md)
312-
313-
314-
315-
316-
317-
313+
- How to [Create a user by using Azure AD B2C custom policy](custom-policies-series-store-user.md)
-60.6 KB
Loading

0 commit comments

Comments
 (0)