Skip to content

Commit e8b49f0

Browse files
committed
Update to Microsoft Entra tutorial
1 parent 5abbf55 commit e8b49f0

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

13/umbraco-cms/tutorials/add-microsoft-entra-id-authentication.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ It is still possible to use other [External Login Providers](../reference/securi
2222

2323
## Step 1: Configure Entra ID
2424

25-
Before your applications can interact with Entra ID, they must be registered with a tenant that you manage. This can be either an Entra ID (Azure AD) tenant, or an Entra ID B2C (Azure AD B2C) tenant. For more information on creating an Azure AD B2C tenant, see [Microsoft's Tutorial: Create an Azure Active Directory B2C tenant](https://learn.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-tenant).
25+
Before your applications can interact with Entra ID, they must be registered with a tenant that you manage. This can be either an Entra ID (Azure AD) tenant, or an Entra ID B2C (Azure AD B2C) tenant. For more information on creating an Azure AD B2C tenant, see [Microsoft's Tutorial: Quickstart: Use your Azure subscription to create an external tenant](https://learn.microsoft.com/en-us/entra/external-id/customers/quickstart-tenant-setup).
26+
27+
To register your web application with your Entra Tenant, follow the instructions in [Register an application in Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app?tabs=client-secret) using the [Microsoft Entra admin center](https://entra.microsoft.com/)
28+
29+
On the "App Registrations" screen, take note of the "Application (Client) Id" value, which will be used in your code later. Then click the "Add a certificate or secret" link.
30+
![Entra Example: App Registration Screen](<../../../13/umbraco-cms/tutorials/images/Entra-Example-App-Registration-ClientCredentials.png>)
31+
32+
Add a new client secret. Be sure to copy the "Value" generated, since you will need to use that in your code as well.
33+
34+
35+
Back on the "Overview" screen, click on the "Add a Redirect URI" link.
36+
37+
Add full urls for all of your applicable environments (local, dev, live, etc.) with the path `/umbraco-b2c-members-signin` added (ex: https://MYSITE.COM/umbraco-b2c-members-signin).
2638

2739
## Step 2: Install the NuGet package
2840

@@ -87,18 +99,21 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
8799
// [OPTIONAL] Callbacks
88100
OnAutoLinking = (autoLinkUser, loginInfo) =>
89101
{
90-
// Customize the Member before it's linked.
91-
// Modify the Members groups based on the Claims returned
92-
// in the external login info.
102+
// You can customize the Member before it's linked.
103+
104+
// Update the Member name based on the Microsoft Account name. (optional)
105+
autoLinkUser.Name = loginInfo.Principal.Identity?.Name;
106+
107+
// You can modify the Member's groups based on the Claims returned in the external login info.
108+
93109
},
94110
OnExternalLogin = (user, loginInfo) =>
95111
{
96-
// Customize the Member before it is saved whenever they have
112+
// You can also update the Member before it is saved whenever they have
97113
// logged in with the external provider.
98-
// Sync the Members name based on the Claims returned
99-
// in the external login info
114+
// For example, re-sync the Member's name based on the Claims returned in the external login info
100115
101-
// Returns a boolean indicating if sign-in should continue or not.
116+
// Return a boolean indicating if sign-in should continue or not.
102117
return true;
103118
}
104119
};
@@ -107,6 +122,10 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
107122
```
108123
{% endcode %}
109124

125+
{% hint style="info" %}
126+
Using "autolinking", if a site visitor attempts to "Sign in with Microsoft" and there is a member in the system with a matching email address, the login will sign in that member. If there is no matching Member, a new one will be created, but by default won't be assigned to any groups.
127+
{% endhint %}
128+
110129
2. Create a new static extension class called `MemberAuthenticationExtensions.cs`.
111130

112131
{% code title="MemberAuthenticationExtensions.cs" lineNumbers="true" %}
@@ -133,8 +152,8 @@ public static class MemberAuthenticationExtensions
133152
options =>
134153
{
135154
// Callbackpath: Represents the URL to which the browser should be redirected to.
136-
// The default value is /signin-oidc.
137155
// This needs to be unique.
156+
// In order to have Umbraco members auto-linked, use "/umbraco-b2c-members-signin"
138157
options.CallbackPath = "/umbraco-b2c-members-signin";
139158

140159
//Obtained from the ENTRA ID B2C WEB APP
@@ -162,6 +181,10 @@ public static class MemberAuthenticationExtensions
162181
Ensure to replace `YOURCLIENTID` and `YOURCLIENTSECRET` in the code with the values from the Entra ID tenant. If Entra ID is configured to use accounts in the organizational directory only (single tenant registration), you must specify the Token and Authorization endpoint. For more information on the differences between single and multi tenant registration, refer to [Microsoft's identity platform documentation](https://learn.microsoft.com/en-us/entra/identity-platform/howto-modify-supported-accounts).
163182
{% endhint %}
164183

184+
{% hint style="info" %}
185+
The Client Secret value will expire at some point and need to be regenerated in the Entra admin center, so you might want to use configurable secret storage to provide the value to your code, rather than hard-coding it.
186+
{% endhint %}
187+
165188
4. Add the Members authentication configuration in the `Program.cs` file:
166189

167190
{% code title="Program.cs" lineNumbers="true" %}
@@ -191,3 +214,5 @@ Learn more about this in the [Dependency Injection](../reference/using-ioc.md) a
191214
6. Run the website.
192215

193216
![Entra ID Login Screen](<../../../10/umbraco-cms/reference/security/images/AD\_Login\_Members (1).png>)
217+
218+
129 KB
Loading

0 commit comments

Comments
 (0)