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/secure-rest-api.md
+31-32Lines changed: 31 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ manager: celestedg
9
9
ms.service: active-directory
10
10
ms.workload: identity
11
11
ms.topic: conceptual
12
-
ms.date: 03/25/2020
12
+
ms.date: 03/26/2020
13
13
ms.author: mimart
14
14
ms.subservice: B2C
15
15
---
@@ -20,7 +20,7 @@ ms.subservice: B2C
20
20
21
21
When integrating a REST API within an Azure AD B2C user journey, you must protect your REST API endpoint with authentication. This ensures that only services that have proper credentials, such as Azure AD B2C, can make calls to your REST API endpoint.
22
22
23
-
Learn how to integrate a REST API within your Azure AD B2C user journey in the [validate user input](custom-policy-rest-api-claims-validation.md), and [Add REST API claims exchanges to custom policies](custom-policy-rest-api-claims-exchange.md) articles.
23
+
Learn how to integrate a REST API within your Azure AD B2C user journey in the [validate user input](custom-policy-rest-api-claims-validation.md) and [Add REST API claims exchanges to custom policies](custom-policy-rest-api-claims-exchange.md) articles.
24
24
25
25
This article will explore how to secure your REST API with either HTTP basic, client certificate or OAuth2 authentication.
26
26
@@ -31,19 +31,19 @@ Complete the steps in one of the following 'How to' guides:
31
31
-[Integrate REST API claims exchanges in your Azure AD B2C user journey to validate user input](custom-policy-rest-api-claims-validation.md).
32
32
-[Add REST API claims exchanges to custom policies](custom-policy-rest-api-claims-exchange.md)
33
33
34
-
## HTTP Basic Authentication
34
+
## HTTP basic authentication
35
35
36
-
HTTP Basic authentication is defined in [RFC 2617](https://tools.ietf.org/html/rfc2617). Basic authentication works as follows, Azure AD B2C sends an HTTP request, with the client credentials in the Authorization header. The credentials are formatted as the string "name:password", base64-encoded.
36
+
HTTP basic authentication is defined in [RFC 2617](https://tools.ietf.org/html/rfc2617). Basic authentication works as follows: Azure AD B2C sends an HTTP request with the client credentials in the Authorization header. The credentials are formatted as the base64-encoded string "name:password".
37
37
38
38
### Add REST API username and password policy keys
39
39
40
-
To configure a REST API technical profile with HTTP Basic Authentication, create the following cryptographic keys to store the username and password:
40
+
To configure a REST API technical profile with HTTP basic authentication, create the following cryptographic keys to store the username and password:
41
41
42
42
1. Sign in to the [Azure portal](https://portal.azure.com/).
43
43
1. Make sure you're using the directory that contains your Azure AD B2C tenant. Select the **Directory + subscription** filter in the top menu and choose your Azure AD B2C directory.
44
44
1. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
45
45
1. On the Overview page, select **Identity Experience Framework**.
46
-
1. Select **Policy Keys** and then select **Add**.
46
+
1. Select **Policy Keys**, and then select **Add**.
47
47
1. For **Options**, select **Manual**.
48
48
1. For **Name**, type **RestApiUsername**.
49
49
The prefix *B2C_1A_* might be added automatically.
@@ -103,7 +103,7 @@ The following is an example of a RESTful technical profile configured with HTTP
103
103
104
104
## HTTPS client certificate authentication
105
105
106
-
Client Certificate Authentication is a mutual certificate-based authentication, where the client, Azure AD B2C provides its Client Certificate to the Server to prove its identity. This happens as a part of the SSL Handshake. Only services that have proper certificates, such as Azure AD B2C, can access your REST API service. The Client Certificate is an X.509 digital certificate and must be signed by a Certificate Authority in Production.
106
+
Client certificate authentication is a mutual certificate-based authentication, where the client, Azure AD B2C, provides its client certificate to the server to prove its identity. This happens as a part of the SSL handshake. Only services that have proper certificates, such as Azure AD B2C, can access your REST API service. The client certificate is an X.509 digital certificate. In production environments, it must be signed by a certificate authority.
107
107
108
108
### Prepare a self-signed certificate (optional)
109
109
@@ -120,19 +120,19 @@ For non-production environments, if you don't already have a certificate, you ca
120
120
-NotAfter (Get-Date).AddMonths(12) `
121
121
-CertStoreLocation "Cert:\CurrentUser\My"
122
122
```
123
-
1. Open **Manage user certificates** > **Current User** > **Personal** > **Certificates** > *yourappname.yourtenant.onmicrosoft.com*
1. Accept the defaults for **Export File Format**.
127
+
1. Provide a password for the certificate.
128
128
129
-
### Add client certificate policy key
129
+
### Add a client certificate policy key
130
130
131
131
1. Sign in to the [Azure portal](https://portal.azure.com/).
132
132
1. Make sure you're using the directory that contains your Azure AD B2C tenant. Select the **Directory + subscription** filter in the top menu and choose your Azure AD B2C directory.
133
133
1. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
134
134
1. On the Overview page, select **Identity Experience Framework**.
135
-
1. Select **Policy Keys** and then select **Add**.
135
+
1. Select **Policy Keys**, and then select **Add**.
136
136
1. In the **Options** box, select **Upload**.
137
137
1. In the **Name** box, type **RestApiClientCertificate**.
138
138
The prefix *B2C_1A_* is added automatically.
@@ -156,7 +156,7 @@ After creating the necessary key, configure your REST API technical profile meta
156
156
</CryptographicKeys>
157
157
```
158
158
159
-
The following is an example of a RESTful technical profile configured with HTTP client certificate:
159
+
The following is an example of a RESTful technical profile configured with an HTTP client certificate:
160
160
161
161
```xml
162
162
<ClaimsProvider>
@@ -180,26 +180,26 @@ The following is an example of a RESTful technical profile configured with HTTP
180
180
</ClaimsProvider>
181
181
```
182
182
183
-
## OAuth2 Bearer authentication
183
+
## OAuth2 bearer authentication
184
184
185
-
Bearer token authentication is defined in [OAuth2.0 Authorization Framework: Bearer Token Usage (RFC 6750)](https://www.rfc-editor.org/rfc/rfc6750.txt). Bearer token authentication works as follows, Azure AD B2C sends an HTTP request, with a token in the Authorization header.
185
+
Bearer token authentication is defined in [OAuth2.0 Authorization Framework: Bearer Token Usage (RFC 6750)](https://www.rfc-editor.org/rfc/rfc6750.txt). In bearer token authentication, Azure AD B2C sends an HTTP request with a token in the authorization header.
186
186
187
187
```http
188
188
Authorization: Bearer <token>
189
189
```
190
190
191
-
A Bearer Token is an opaque string. It can be a JWT access token or any string the REST API expecting Azure AD B2C to send in the Authorization header. Azure AD B2C supports:
191
+
A bearer token is an opaque string. It can be a JWT access token or any string that the REST API expects Azure AD B2C to send in the authorization header. Azure AD B2C supports the following types:
192
192
193
-
-A bearer token - To be able to send the bearer token in the Restful technical profile, your policy needs first to acquire the bearer token and then use it in the RESTful technical profile.
194
-
-A static bearer token - Use this approach when your REST API issues a log term access token. To use a static bearer token, create a policy key and make a reference from the RESTful technical profile to your policy key.
193
+
-**Bearer token**. To be able to send the bearer token in the Restful technical profile, your policy needs to first acquire the bearer token and then use it in the RESTful technical profile.
194
+
-**Static bearer token**. Use this approach when your REST API issues a long-term access token. To use a static bearer token, create a policy key and make a reference from the RESTful technical profile to your policy key.
195
195
196
196
## Using OAuth2 Bearer
197
197
198
-
The following demonstrates how to use client credentials to obtain a bearer token and then pass this into the Authorization header of the REST API calls.
198
+
The following steps demonstrate how to use client credentials to obtain a bearer token and pass it into the Authorization header of the REST API calls.
199
199
200
-
### Define a Claim to store the bearer token
200
+
### Define a claim to store the bearer token
201
201
202
-
A claim provides a temporary storage of data during an Azure AD B2C policy execution. The [claims schema](claimsschema.md) is the place where you declare your claims. The access token must be stored in a claim to be used later.
202
+
A claim provides temporary storage of data during an Azure AD B2C policy execution. The [claims schema](claimsschema.md) is the place where you declare your claims. The access token must be stored in a claim to be used later.
203
203
204
204
1. Open the extensions file of your policy. For example, <em>`SocialAndLocalAccounts/`**`TrustFrameworkExtensions.xml`**</em>.
205
205
1. Search for the [BuildingBlocks](buildingblocks.md) element. If the element doesn't exist, add it.
@@ -215,9 +215,9 @@ A claim provides a temporary storage of data during an Azure AD B2C policy execu
215
215
216
216
### Acquiring an access token
217
217
218
-
You may obtain your access token from a federated identity provider, calling a REST API that returns an access token, or using client the credentials flow.
218
+
You can obtain an access token from a federated identity provider by calling a REST API that returns an access token or by using the client credentials flow.
219
219
220
-
The following example uses a REST API Technical profile to make a request to the Azure AD Token endpoint using the client credentials passed as HTTP Basic authentication. To configure this in Azure AD, see [Microsoft identity platform and the OAuth 2.0 client credentials flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow).
220
+
The following example uses a REST API technical profile to make a request to the Azure AD token endpoint using the client credentials passed as HTTP basic authentication. To configure this in Azure AD, see [Microsoft identity platform and the OAuth 2.0 client credentials flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow).
221
221
222
222
You may need to modify this to interface with your Identity Provider. See the [RESTful technical profile](restful-technical-profile.md) reference for all options available.
223
223
@@ -245,9 +245,9 @@ You may need to modify this to interface with your Identity Provider. See the [R
245
245
</TechnicalProfile>
246
246
```
247
247
248
-
### Change the REST technical profile to use Bearer Token Authentication
248
+
### Change the REST technical profile to use bearer token authentication
249
249
250
-
To support Bearer Token authentication in your custom policy, modify the REST API technical profile with the following:
250
+
To support bearer token authentication in your custom policy, modify the REST API technical profile with the following:
251
251
252
252
1. In your working directory, open the *TrustFrameworkExtensions.xml* extension policy file.
253
253
1. Search for the `<TechnicalProfile>` node that includes `Id="REST-API-SignUp"`.
@@ -256,12 +256,11 @@ To support Bearer Token authentication in your custom policy, modify the REST AP
256
256
```xml
257
257
<ItemKey="AuthenticationType">Bearer</Item>
258
258
```
259
-
1. Change/Add the *UseClaimAsBearerToken* to *bearerToken*, as follows:
259
+
1. Change or add the *UseClaimAsBearerToken* to *bearerToken*, as follows. The *bearerToken* is the name of the claim that the bearer token will be retrieved from (the output claim from `SecureREST-AccessToken`).
(bearerToken is the name of the claim the Bearer token will be retrieved from - the output claim from `SecureREST-AccessToken`)
265
264
266
265
1. Ensure you add the claim used above as an input claim:
267
266
@@ -294,7 +293,7 @@ After you add the above snippets, your technical profile should look like the fo
294
293
</ClaimsProvider>
295
294
```
296
295
297
-
## Using a static OAuth2 Bearer
296
+
## Using a static OAuth2 bearer
298
297
299
298
### Add the OAuth2 bearer token policy key
300
299
@@ -304,7 +303,7 @@ Create a policy key to store the bearer token value.
304
303
1. Make sure you're using the directory that contains your Azure AD B2C tenant. Select the **Directory + subscription** filter in the top menu and choose your Azure AD B2C directory.
305
304
1. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
306
305
1. On the Overview page, select **Identity Experience Framework**.
307
-
1. Select **Policy Keys** and then select **Add**.
306
+
1. Select **Policy Keys**, and then select **Add**.
308
307
1. For **Options**, choose `Manual`.
309
308
1. Enter a **Name** for the policy key. For example, `RestApiBearerToken`. The prefix `B2C_1A_` is added automatically to the name of your key.
310
309
1. In **Secret**, enter your client secret that you previously recorded.
@@ -353,4 +352,4 @@ The following is an example of a RESTful technical profile configured with beare
353
352
354
353
## Next steps
355
354
356
-
- Learn more about [Restful technical profile](restful-technical-profile.md) element in the IEF reference.
355
+
- Learn more about the [Restful technical profile](restful-technical-profile.md) element in the IEF reference.
0 commit comments