Skip to content

Commit 92ec9c7

Browse files
authored
Merge pull request #7418 from hfloyd/feature/v13EntraUpdate
Update to Microsoft Entra tutorial
2 parents b7873b4 + 721fb39 commit 92ec9c7

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

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

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ 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+
Follow these steps to register your web application with your Entra tenant and configure it for member sign-in:
28+
29+
1. 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/).
30+
31+
2. On the **App Registrations** screen, copy the **Application (Client) ID** value. You will need this in your code later.
32+
3. Click **Add a certificate or secret**.
33+
34+
![Entra Example: App Registration Screen](<../../../13/umbraco-cms/tutorials/images/Entra-Example-App-Registration-ClientCredentials.png>)
35+
36+
4. Add a new client secret and copy the generated **Value**. You will use this in your code as well.
37+
38+
39+
5. Return to the **Overview** screen and click **Add a Redirect URI**.
40+
41+
6. Add full URLs for all of your applicable environments (local, dev, live, etc.) with the path `/umbraco-b2c-members-signin` appended. For example, `https://mysite.com/umbraco-b2c-members-signin`.
2642

2743
## Step 2: Install the NuGet package
2844

@@ -59,9 +75,11 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
5975

6076
public void Configure(MemberExternalLoginProviderOptions options)
6177
{
62-
// The following options are relevant if you
63-
// want to configure auto-linking on the authentication.
64-
options.AutoLinkOptions = new MemberExternalSignInAutoLinkOptions(
78+
79+
// The following options are relevant if you
80+
// want to configure auto-linking on the authentication.
81+
82+
options.AutoLinkOptions = new MemberExternalSignInAutoLinkOptions(
6583

6684
// Set to true to enable auto-linking
6785
autoLinkExternalAccount: true,
@@ -87,18 +105,21 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
87105
// [OPTIONAL] Callbacks
88106
OnAutoLinking = (autoLinkUser, loginInfo) =>
89107
{
90-
// Customize the Member before it's linked.
91-
// Modify the Members groups based on the Claims returned
92-
// in the external login info.
108+
// You can customize the Member before it's linked.
109+
110+
// Update the Member name based on the Microsoft Account name. (optional)
111+
autoLinkUser.Name = loginInfo.Principal.Identity?.Name;
112+
113+
// You can modify the Member's groups based on the Claims returned in the external login info.
114+
93115
},
94116
OnExternalLogin = (user, loginInfo) =>
95117
{
96-
// Customize the Member before it is saved whenever they have
118+
// You can also update the Member before it is saved whenever they have
97119
// logged in with the external provider.
98-
// Sync the Members name based on the Claims returned
99-
// in the external login info
120+
// For example, re-sync the Member's name based on the Claims returned in the external login info
100121
101-
// Returns a boolean indicating if sign-in should continue or not.
122+
// Return a boolean indicating if sign-in should continue or not.
102123
return true;
103124
}
104125
};
@@ -107,6 +128,12 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
107128
```
108129
{% endcode %}
109130

131+
{% hint style="info" %}
132+
133+
With **autolinking**, if a visitor uses **Sign in with Microsoft** and their email matches a member, that member is signed in. If no matching member exists, a new one is created. By default, it isn’t assigned to any groups.
134+
135+
{% endhint %}
136+
110137
2. Create a new static extension class called `MemberAuthenticationExtensions.cs`.
111138

112139
{% code title="MemberAuthenticationExtensions.cs" lineNumbers="true" %}
@@ -133,8 +160,8 @@ public static class MemberAuthenticationExtensions
133160
options =>
134161
{
135162
// Callbackpath: Represents the URL to which the browser should be redirected to.
136-
// The default value is /signin-oidc.
137163
// This needs to be unique.
164+
// In order to have Umbraco members auto-linked, use "/umbraco-b2c-members-signin"
138165
options.CallbackPath = "/umbraco-b2c-members-signin";
139166

140167
//Obtained from the ENTRA ID B2C WEB APP
@@ -159,7 +186,15 @@ public static class MemberAuthenticationExtensions
159186
{% endcode %}
160187

161188
{% hint style="info" %}
189+
162190
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).
191+
192+
{% endhint %}
193+
194+
{% hint style="warning" %}
195+
196+
The Client Secret value will expire and must be regenerated in the Entra admin center. Use configurable secret storage to provide the value to your code, rather than hard-coding it.
197+
163198
{% endhint %}
164199

165200
4. Add the Members authentication configuration in the `Program.cs` file:
@@ -180,11 +215,13 @@ builder.CreateUmbracoBuilder()
180215
{% endcode %}
181216

182217
{% hint style="info" %}
218+
183219
Are you building a package for Umbraco?
184220

185221
Then you will not have access to the `Program.cs` file. Instead you need to create a composer in order to register your extension method.
186222

187223
Learn more about this in the [Dependency Injection](../reference/using-ioc.md) article.
224+
188225
{% endhint %}
189226

190227
5. Build the project.
129 KB
Loading

0 commit comments

Comments
 (0)