Skip to content

Commit b6e91ee

Browse files
authored
Merge pull request #88194 from mmacy/b2c-ad-appreg-v2-custpol
[b2c] AD app reg v2 (custom policies)
2 parents 951d6f9 + 81b7e90 commit b6e91ee

File tree

2 files changed

+153
-128
lines changed

2 files changed

+153
-128
lines changed
Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Set up sign-in with an Azure Active Directory account in Azure Active Directory B2C using custom policies | Microsoft Docs
2+
title: Set up sign-in with an Azure Active Directory account in Azure Active Directory B2C using custom policies
33
description: Set up sign in with an Azure Active Directory account in Azure Active Directory B2C using custom policies.
44
services: active-directory-b2c
55
author: mmacy
@@ -8,12 +8,12 @@ manager: celestedg
88
ms.service: active-directory
99
ms.workload: identity
1010
ms.topic: conceptual
11-
ms.date: 09/20/2018
11+
ms.date: 09/13/2019
1212
ms.author: marsma
1313
ms.subservice: B2C
1414
---
1515

16-
# Set up sign-in with an Azure Active Directory account using custom policies in Azure Active Directory B2C
16+
# Set up sign-in with an Azure Active Directory account using custom policies in Azure Active Directory B2C
1717

1818
[!INCLUDE [active-directory-b2c-advanced-audience-warning](../../includes/active-directory-b2c-advanced-audience-warning.md)]
1919

@@ -28,44 +28,44 @@ Complete the steps in [Get started with custom policies in Azure Active Director
2828
To enable sign-in for users from a specific Azure AD organization, you need to register an application within the organizational Azure AD tenant.
2929

3030
1. Sign in to the [Azure portal](https://portal.azure.com).
31-
2. Make sure you're using the directory that contains organizational Azure AD tenant (contoso.com) by clicking the **Directory and subscription filter** in the top menu and choosing the directory that contains your tenant.
32-
3. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **App registrations**.
33-
4. Select **New application registration**.
34-
5. Enter a name for your application. For example, `Azure AD B2C App`.
35-
6. For the **Application type**, select `Web app / API`.
36-
7. For the **Sign-on URL**, enter the following URL in all lowercase letters, where `your-B2C-tenant-name` is replaced with the name of your Azure AD B2C tenant:
31+
1. Make sure you're using the directory that contains your organizational Azure AD tenant (for example, contoso.com). Select the **Directory + subscription filter** in the top menu, and then choose the directory that contains your Azure AD tenant.
32+
1. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **App registrations**.
33+
1. Select **New registration**.
34+
1. Enter a **Name** for your application. For example, `Azure AD B2C App`.
35+
1. Accept the default selection of **Accounts in this organizational directory only** for this application.
36+
1. For the **Redirect URI**, accept the value of **Web**, and enter the following URL in all lowercase letters, where `your-B2C-tenant-name` is replaced with the name of your Azure AD B2C tenant.
3737

3838
```
3939
https://your-B2C-tenant-name.b2clogin.com/your-B2C-tenant-name.onmicrosoft.com/oauth2/authresp
4040
```
4141
4242
For example, `https://contoso.b2clogin.com/contoso.onmicrosoft.com/oauth2/authresp`.
4343
44-
8. Click **Create**. Copy the **Application ID** to be used later.
45-
9. Select the application, and then select **Settings**.
46-
10. Select **Keys**, enter the key description, select a duration, and then click **Save**. Copy the value of the key that is displayed to be used later.
44+
1. Select **Register**. Record the **Application (client) ID** for use in a later step.
45+
1. Select **Certificates & secrets**, and then select **New client secret**.
46+
1. Enter a **Description** for the secret, select an expiration, and then select **Add**. Record the **VALUE** of the secret for use in a later step.
4747
4848
## Create a policy key
4949
5050
You need to store the application key that you created in your Azure AD B2C tenant.
5151
52-
1. Make sure you're using the directory that contains your Azure AD B2C tenant by clicking the **Directory and subscription filter** in the top menu and choosing the directory that contains your tenant.
53-
2. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
54-
3. On the Overview page, select **Identity Experience Framework**.
55-
4. Select **Policy Keys** and then select **Add**.
56-
5. For **Options**, choose `Manual`.
57-
6. Enter a **Name** for the policy key. For example, `ContosoAppSecret`. The prefix `B2C_1A_` is added automatically to the name of your key.
58-
7. In **Secret**, enter your application key that you previously recorded.
59-
8. For **Key usage**, select `Signature`.
60-
9. Click **Create**.
52+
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 then choose the directory that contains your Azure AD B2C tenant.
53+
1. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
54+
1. Under **Policies**, select **Identity Experience Framework**.
55+
1. Select **Policy keys** and then select **Add**.
56+
1. For **Options**, choose `Manual`.
57+
1. Enter a **Name** for the policy key. For example, `ContosoAppSecret`. The prefix `B2C_1A_` is added automatically to the name of your key when it's created, so its reference in the XML in following section is to *B2C_1A_ContosoAppSecret*.
58+
1. In **Secret**, enter your client secret that you recorded earlier.
59+
1. For **Key usage**, select `Signature`.
60+
1. Select **Create**.
6161
6262
## Add a claims provider
6363
64-
If you want users to sign in by using Azure AD, you need to define Azure AD as a claims provider that Azure AD B2C can communicate with through an endpoint. The endpoint provides a set of claims that are used by Azure AD B2C to verify that a specific user has authenticated.
64+
If you want users to sign in by using Azure AD, you need to define Azure AD as a claims provider that Azure AD B2C can communicate with through an endpoint. The endpoint provides a set of claims that are used by Azure AD B2C to verify that a specific user has authenticated.
6565
6666
You can define Azure AD as a claims provider by adding Azure AD to the **ClaimsProvider** element in the extension file of your policy.
6767
68-
1. Open the *TrustFrameworkExtensions.xml*.
68+
1. Open the *TrustFrameworkExtensions.xml* file.
6969
2. Find the **ClaimsProviders** element. If it does not exist, add it under the root element.
7070
3. Add a new **ClaimsProvider** as follows:
7171
@@ -78,17 +78,16 @@ You can define Azure AD as a claims provider by adding Azure AD to the **ClaimsP
7878
<DisplayName>Contoso Employee</DisplayName>
7979
<Description>Login with your Contoso account</Description>
8080
<Protocol Name="OpenIdConnect"/>
81-
<OutputTokenFormat>JWT</OutputTokenFormat>
8281
<Metadata>
8382
<Item Key="METADATA">https://login.windows.net/your-AD-tenant-name.onmicrosoft.com/.well-known/openid-configuration</Item>
8483
<Item Key="ProviderName">https://sts.windows.net/00000000-0000-0000-0000-000000000000/</Item>
84+
<!-- Update the Client ID below to the Application ID -->
8585
<Item Key="client_id">00000000-0000-0000-0000-000000000000</Item>
86-
<Item Key="IdTokenAudience">00000000-0000-0000-0000-000000000000</Item>
87-
<Item Key="UsePolicyInRedirectUri">false</Item>
8886
<Item Key="response_types">code</Item>
8987
<Item Key="scope">openid</Item>
9088
<Item Key="response_mode">form_post</Item>
9189
<Item Key="HttpBinding">POST</Item>
90+
<Item Key="UsePolicyInRedirectUri">false</Item>
9291
</Metadata>
9392
<CryptographicKeys>
9493
<Key Id="client_secret" StorageReferenceId="B2C_1A_ContosoAppSecret"/>
@@ -100,7 +99,7 @@ You can define Azure AD as a claims provider by adding Azure AD to the **ClaimsP
10099
<OutputClaim ClaimTypeReferenceId="surName" PartnerClaimType="family_name" />
101100
<OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
102101
<OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication" AlwaysUseDefaultValue="true" />
103-
<OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="AzureADContoso" AlwaysUseDefaultValue="true" />
102+
<OutputClaim ClaimTypeReferenceId="identityProvider" PartnerClaimType="iss" />
104103
</OutputClaims>
105104
<OutputClaimsTransformations>
106105
<OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/>
@@ -122,38 +121,38 @@ You can define Azure AD as a claims provider by adding Azure AD to the **ClaimsP
122121
To get a token from the Azure AD endpoint, you need to define the protocols that Azure AD B2C should use to communicate with Azure AD. This is done inside the **TechnicalProfile** element of **ClaimsProvider**.
123122
124123
1. Update the ID of the **TechnicalProfile** element. This ID is used to refer to this technical profile from other parts of the policy.
125-
2. Update the value for **DisplayName**. This value will be displayed on the sign-in button on your sign-in screen.
126-
3. Update the value for **Description**.
127-
4. Azure AD uses the OpenID Connect protocol, so make sure that the value for **Protocol** is `OpenIdConnect`.
128-
5. Set value of the **METADATA** to `https://login.windows.net/your-AD-tenant-name.onmicrosoft.com/.well-known/openid-configuration`, where `your-AD-tenant-name` is your Azure AD tenant name. For example, `https://login.windows.net/fabrikam.onmicrosoft.com/.well-known/openid-configuration`
129-
6. Open your browser and go to the **METADATA** URL that you just updated, look for the **issuer** object, copy and paste the value into the value for **ProviderName** in the XML file.
130-
8. Set **client_id** and **IdTokenAudience** to the application ID from the application registration.
131-
9. Under **CryptographicKeys**, Update the value for **StorageReferenceId** to the policy key that you defined. For example, `ContosoAppSecret`.
124+
1. Update the value for **DisplayName**. This value will be displayed on the sign-in button on your sign-in screen.
125+
1. Update the value for **Description**.
126+
1. Azure AD uses the OpenID Connect protocol, so make sure that the value for **Protocol** is `OpenIdConnect`.
127+
1. Set value of the **METADATA** to `https://login.windows.net/your-AD-tenant-name.onmicrosoft.com/.well-known/openid-configuration`, where `your-AD-tenant-name` is your Azure AD tenant name. For example, `https://login.windows.net/fabrikam.onmicrosoft.com/.well-known/openid-configuration`
128+
1. Open your browser and go to the **METADATA** URL that you just updated, look for the **issuer** object, and then copy and paste the value into the value for **ProviderName** in the XML file.
129+
1. Set **client_id** to the application ID from the application registration.
130+
1. Under **CryptographicKeys**, update the value of **StorageReferenceId** to the name of the policy key that you created earlier. For example, `B2C_1A_ContosoAppSecret`.
132131
133132
### Upload the extension file for verification
134133
135134
By now, you have configured your policy so that Azure AD B2C knows how to communicate with your Azure AD directory. Try uploading the extension file of your policy just to confirm that it doesn't have any issues so far.
136135
137136
1. On the **Custom Policies** page in your Azure AD B2C tenant, select **Upload Policy**.
138-
2. Enable **Overwrite the policy if it exists**, and then browse to and select the *TrustFrameworkExtensions.xml* file.
139-
3. Click **Upload**.
137+
1. Enable **Overwrite the policy if it exists**, and then browse to and select the *TrustFrameworkExtensions.xml* file.
138+
1. Click **Upload**.
140139
141140
## Register the claims provider
142141
143-
At this point, the identity provider has been set up, but its not available in any of the sign-up/sign-in screens. To make it available, you create a duplicate of an existing template user journey, and then modify it so that it also has the Azure AD identity provider:
142+
At this point, the identity provider has been set up, but it's not yet available in any of the sign-up/sign-in pages. To make it available, create a duplicate of an existing template user journey, and then modify it so that it also has the Azure AD identity provider:
144143
145144
1. Open the *TrustFrameworkBase.xml* file from the starter pack.
146-
2. Find and copy the entire contents of the **UserJourney** element that includes `Id="SignUpOrSignIn"`.
147-
3. Open the *TrustFrameworkExtensions.xml* and find the **UserJourneys** element. If the element doesn't exist, add one.
148-
4. Paste the entire content of the **UserJourney** element that you copied as a child of the **UserJourneys** element.
149-
5. Rename the ID of the user journey. For example, `SignUpSignInContoso`.
145+
1. Find and copy the entire contents of the **UserJourney** element that includes `Id="SignUpOrSignIn"`.
146+
1. Open the *TrustFrameworkExtensions.xml* and find the **UserJourneys** element. If the element doesn't exist, add one.
147+
1. Paste the entire content of the **UserJourney** element that you copied as a child of the **UserJourneys** element.
148+
1. Rename the ID of the user journey. For example, `SignUpSignInContoso`.
150149
151150
### Display the button
152151
153-
The **ClaimsProviderSelection** element is analogous to an identity provider button on a sign-up/sign-in screen. If you add a **ClaimsProviderSelection** element for Azure AD, a new button shows up when a user lands on the page.
152+
The **ClaimsProviderSelection** element is analogous to an identity provider button on a sign-up/sign-in page. If you add a **ClaimsProviderSelection** element for Azure AD, a new button shows up when a user lands on the page.
154153
155-
1. Find the **OrchestrationStep** element that includes `Order="1"` in the user journey that you created.
156-
2. Under **ClaimsProviderSelections**, add the following element. Set the value of **TargetClaimsExchangeId** to an appropriate value, for example `ContosoExchange`:
154+
1. Find the **OrchestrationStep** element that includes `Order="1"` in the user journey that you created in *TrustFrameworkExtensions.xml*.
155+
1. Under **ClaimsProviderSelections**, add the following element. Set the value of **TargetClaimsExchangeId** to an appropriate value, for example `ContosoExchange`:
157156
158157
```XML
159158
<ClaimsProviderSelection TargetClaimsExchangeId="ContosoExchange" />
@@ -164,36 +163,46 @@ The **ClaimsProviderSelection** element is analogous to an identity provider but
164163
Now that you have a button in place, you need to link it to an action. The action, in this case, is for Azure AD B2C to communicate with Azure AD to receive a token. Link the button to an action by linking the technical profile for your Azure AD claims provider:
165164
166165
1. Find the **OrchestrationStep** that includes `Order="2"` in the user journey.
167-
2. Add the following **ClaimsExchange** element making sure that you use the same value for **Id** that you used for **TargetClaimsExchangeId**:
166+
1. Add the following **ClaimsExchange** element making sure that you use the same value for **Id** that you used for **TargetClaimsExchangeId**:
168167
169168
```XML
170169
<ClaimsExchange Id="ContosoExchange" TechnicalProfileReferenceId="ContosoProfile" />
171170
```
172-
171+
173172
Update the value of **TechnicalProfileReferenceId** to the **Id** of the technical profile you created earlier. For example, `ContosoProfile`.
174173
175-
3. Save the *TrustFrameworkExtensions.xml* file and upload it again for verification.
174+
1. Save the *TrustFrameworkExtensions.xml* file and upload it again for verification.
176175
177176
## Create an Azure AD B2C application
178177
179-
Communication with Azure AD B2c occurs through an application that you create in your tenant. This section lists optional steps you can complete to create a test application if you haven't already done so.
178+
Communication with Azure AD B2C occurs through an application that you register in your B2C tenant. This section lists optional steps you can complete to create a test application if you haven't already done so.
180179
181180
1. Sign in to the [Azure portal](https://portal.azure.com).
182-
2. Make sure you're using the directory that contains your Azure AD B2C tenant by clicking the **Directory and subscription filter** in the top menu and choosing the directory that contains your tenant.
183-
3. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
184-
4. Select **Applications**, and then select **Add**.
185-
5. Enter a name for the application, for example *testapp1*.
186-
6. For **Web App / Web API**, select `Yes`, and then enter `https://jwt.ms` for the **Reply URL**.
187-
7. Click **Create**.
181+
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 then choose the directory that contains your Azure AD B2C tenant.
182+
1. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**.
183+
1. Select **Applications**, and then select **Add**.
184+
1. Enter a name for the application, for example *testapp1*.
185+
1. For **Web App / Web API**, select `Yes`, and then enter `https://jwt.ms` for the **Reply URL**.
186+
1. Select **Create**.
188187
189188
## Update and test the relying party file
190189
191190
Update the relying party (RP) file that initiates the user journey that you created.
192191
193192
1. Make a copy of *SignUpOrSignIn.xml* in your working directory, and rename it. For example, rename it to *SignUpSignInContoso.xml*.
194-
2. Open the new file and update the value of the **PolicyId** attribute for **TrustFrameworkPolicy** with a unique value. For example, `SignUpSignInContoso`.
195-
3. Update the value of **PublicPolicyUri** with the URI for the policy. For example,`http://contoso.com/B2C_1A_signup_signin_contoso`
196-
4. Update the value of the **ReferenceId** attribute in **DefaultUserJourney** to match the ID of the new user journey that you created (SignUpSignInContoso).
197-
5. Save your changes, upload the file, and then select the new policy in the list.
198-
6. Make sure that Azure AD B2C application that you created is selected in the **Select application** field, and then test it by clicking **Run now**.
193+
1. Open the new file and update the value of the **PolicyId** attribute for **TrustFrameworkPolicy** with a unique value. For example, `SignUpSignInContoso`.
194+
1. Update the value of **PublicPolicyUri** with the URI for the policy. For example, `http://contoso.com/B2C_1A_signup_signin_contoso`.
195+
1. Update the value of the **ReferenceId** attribute in **DefaultUserJourney** to match the ID of the user journey that you created earlier. For example, *SignUpSignInContoso*.
196+
1. Save your changes and upload the file.
197+
1. Under **Custom policies**, select the new policy in the list.
198+
1. In the **Select application** drop-down, select the Azure AD B2C application that you created earlier. For example, *testapp1*.
199+
1. Copy the **Run now endpoint** and open it in a private browser window, for example, Incognito Mode in Google Chrome or an InPrivate window in Microsoft Edge. Opening in a private browser window allows you to test the full user journey by not using any currently cached Azure AD credentials.
200+
1. Select the Azure AD sign in button, for example, *Contoso Employee*, and then enter the credentials for a user in your Azure AD organizational tenant. You're asked to authorize the application, and then enter information for your profile.
201+
202+
If the sign in process is successful, your browser is redirected to `https://jwt.ms`, which displays the contents of the token returned by Azure AD B2C.
203+
204+
## Next steps
205+
206+
When working with custom policies, you might sometimes need additional information when troubleshooting a policy during its development.
199207
208+
To help diagnose issues, you can temporarily put the policy into "developer mode" and collect logs with Azure Application Insights. Find out how in [Azure Active Directory B2C: Collecting Logs](active-directory-b2c-troubleshoot-custom.md).

0 commit comments

Comments
 (0)