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: 13/umbraco-cms/tutorials/add-microsoft-entra-id-authentication.md
+34-9Lines changed: 34 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,19 @@ It is still possible to use other [External Login Providers](../reference/securi
22
22
23
23
## Step 1: Configure Entra ID
24
24
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.
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).
26
38
27
39
## Step 2: Install the NuGet package
28
40
@@ -87,18 +99,21 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
87
99
// [OPTIONAL] Callbacks
88
100
OnAutoLinking= (autoLinkUser, loginInfo) =>
89
101
{
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)
// You can modify the Member's groups based on the Claims returned in the external login info.
108
+
93
109
},
94
110
OnExternalLogin= (user, loginInfo) =>
95
111
{
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
97
113
// 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
100
115
101
-
//Returns a boolean indicating if sign-in should continue or not.
116
+
//Return a boolean indicating if sign-in should continue or not.
102
117
returntrue;
103
118
}
104
119
};
@@ -107,6 +122,10 @@ public class EntraIDB2CMembersExternalLoginProviderOptions : IConfigureNamedOpti
107
122
```
108
123
{% endcode %}
109
124
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
+
110
129
2. Create a new static extension class called `MemberAuthenticationExtensions.cs`.
@@ -162,6 +181,10 @@ public static class MemberAuthenticationExtensions
162
181
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).
163
182
{% endhint %}
164
183
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
+
165
188
4. Add the Members authentication configuration in the `Program.cs` file:
166
189
167
190
{% code title="Program.cs" lineNumbers="true" %}
@@ -191,3 +214,5 @@ Learn more about this in the [Dependency Injection](../reference/using-ioc.md) a
191
214
6. Run the website.
192
215
193
216
.png>)
0 commit comments