Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/36 #37

Merged
merged 3 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cls
SET NODE_ENV=development&&SET CUSTOM_DEV=&& webpack-dev-server
SET NODE_ENV=development&&SET CUSTOM_DEV=&&SET NODE_OPTIONS=--openssl-legacy-provider&& webpack-dev-server
12 changes: 6 additions & 6 deletions DotNetNuke.Authentication.Azure.B2C/AzureADB2CProvider.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="AzureADB2CProvider" type="Auth_System" version="01.05.01">
<package name="AzureADB2CProvider" type="Auth_System" version="01.06.00">
<friendlyName>DNN Azure Active Directory B2C Provider</friendlyName>
<description>The DNN Azure Active Directory B2C Provider is an Authentication provider for DNN Platform that uses Azure Active Directory B2C OAuth2 authentication to authenticate users.</description>
<iconFile>~/DesktopModules/AuthenticationServices/AzureB2C/Images/azure.png</iconFile>
Expand All @@ -14,7 +14,7 @@
<releaseNotes src="AzureADB2CReleaseNotes.txt"/>
<azureCompatible>true</azureCompatible>
<dependencies>
<dependency type="CoreVersion">09.04.03</dependency>
<dependency type="CoreVersion">09.11.00</dependency>
<dependency type="ManagedPackage" version="01.00.00">Dnn.PersonaBar.UI</dependency>
</dependencies>

Expand Down Expand Up @@ -246,7 +246,7 @@
</components>
</package>

<package name="AzureADB2CProvider" type="Module" version="01.05.01">
<package name="AzureADB2CProvider" type="Module" version="01.06.00">
<friendlyName>DNN Azure Active Directory B2C User Management</friendlyName>
<description>The DNN Azure Active Directory B2C Provider is an Authentication provider for DNN Platform that uses Azure Active Directory B2C OAuth2 authentication to authenticate users.</description>
<iconFile>~/DesktopModules/AuthenticationServices/AzureB2C/Images/azure.png</iconFile>
Expand All @@ -260,7 +260,7 @@
<releaseNotes src="AzureADB2CReleaseNotes.txt"/>
<azureCompatible>true</azureCompatible>
<dependencies>
<dependency type="CoreVersion">09.04.03</dependency>
<dependency type="CoreVersion">09.11.00</dependency>
</dependencies>

<components>
Expand Down Expand Up @@ -307,7 +307,7 @@
</components>
</package>

<package name="AzureADB2CProvider" type="Module" version="01.05.01">
<package name="AzureADB2CProvider" type="Module" version="01.06.00">
<friendlyName>DNN Azure Active Directory B2C Impersonate</friendlyName>
<description>The DNN Azure Active Directory B2C Provider is an Authentication provider for DNN Platform that uses Azure Active Directory B2C OAuth2 authentication to authenticate users.</description>
<iconFile>~/DesktopModules/AuthenticationServices/AzureB2C/Images/azure.png</iconFile>
Expand All @@ -321,7 +321,7 @@
<releaseNotes src="AzureADB2CReleaseNotes.txt"/>
<azureCompatible>true</azureCompatible>
<dependencies>
<dependency type="CoreVersion">09.04.03</dependency>
<dependency type="CoreVersion">09.11.00</dependency>
</dependencies>

<components>
Expand Down
11 changes: 11 additions & 0 deletions DotNetNuke.Authentication.Azure.B2C/AzureADB2CReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@
<li>Fixed impersonation error for new users with no extension fields set</li>
<li>Fix error on group sync scheduler task</li>
<li>Removed Microsoft.IdentityModel.Clients.ActiveDirectory depedency</li>
</ul>

<p style="margin-top: 20px"><b>Version 01.06.00</b></p>
<ul style="margin: 5px 0 0 30px">
<li>The module now requires DNN v9.11 or later</li>
<li>Updated dependencies to latest versions</li>
<li>Updated Dnn.React.Common dependency to 9.11</li>
<li>Fix to update users by Username in the User Management module</li>
<li>Fix to correctly expire the B2C cookie with the token expiration date</li>
<li>Upgraded project to .NET 4.8</li>
<li>Updated Sample SPA Web Client to use 9.11 or later</li>
</ul>
17 changes: 11 additions & 6 deletions DotNetNuke.Authentication.Azure.B2C/Components/AzureClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public enum PolicyEnum
public const string RoleSettingsB2cPropertyName = "IdentitySource";
public const string RoleSettingsB2cPropertyValue = "Azure-B2C";

private const string TokenEndpointPattern = "https://{0}.b2clogin.com/{1}/oauth2/v2.0/token";
private const string LogoutEndpointPattern = "https://{0}.b2clogin.com/{1}/oauth2/v2.0/logout?p={2}&post_logout_redirect_uri={3}";
internal const string AuthorizationEndpointPattern = "https://{0}.b2clogin.com/{1}/oauth2/v2.0/authorize";
private const string TokenEndpointPattern = "https://{0}/{1}/oauth2/v2.0/token";
private const string LogoutEndpointPattern = "https://{0}/{1}/oauth2/v2.0/logout?p={2}&post_logout_redirect_uri={3}";
internal const string AuthorizationEndpointPattern = "https://{0}/{1}/oauth2/v2.0/authorize";
private const string GraphEndpointPattern = "https://graph.windows.net/{0}";

private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(AzureClient));
Expand Down Expand Up @@ -290,9 +290,14 @@ public AzureClient(int portalId, AuthMode mode)

if (!string.IsNullOrEmpty(Settings.TenantName) && !string.IsNullOrEmpty(Settings.TenantId))
{
TokenEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.TokenEndpointPattern", TokenEndpointPattern), Settings.TenantName, Settings.TenantId));
LogoutEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.LogoutEndpointPattern", LogoutEndpointPattern), Settings.TenantName, Settings.TenantId, Settings.SignUpPolicy, UrlEncode(HttpContext.Current.Request.Url.ToString())));
AuthorizationEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.AuthorizationEndpointPattern", AuthorizationEndpointPattern), Settings.TenantName, Settings.TenantId));
var tenantName = Settings.TenantName;
if (!tenantName.Contains("."))
{
tenantName += ".b2clogin.com";
}
TokenEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.TokenEndpointPattern", TokenEndpointPattern), tenantName, Settings.TenantId));
LogoutEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.LogoutEndpointPattern", LogoutEndpointPattern), tenantName, Settings.TenantId, Settings.SignUpPolicy, UrlEncode(HttpContext.Current.Request.Url.ToString())));
AuthorizationEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.AuthorizationEndpointPattern", AuthorizationEndpointPattern), tenantName, Settings.TenantId));
MeGraphEndpoint = new Uri(string.Format(Utils.GetAppSetting("AzureADB2C.GraphEndpointPattern", GraphEndpointPattern), Settings.TenantId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ internal static B2CControllerConfiguration GetConfig(int portalId, AzureConfig a
if (currentConfig == null)
{
var ropcPolicyName = !string.IsNullOrEmpty(azureB2cConfig.RopcPolicy) ? azureB2cConfig.RopcPolicy : DefaultRopcPolicy;
var tokenConfigurationUrl = $"https://{azureB2cConfig.TenantName}.b2clogin.com/{azureB2cConfig.TenantId}/.well-known/openid-configuration?p={ropcPolicyName}";
var tenantName = azureB2cConfig.TenantName;
if (!tenantName.Contains("."))
{
tenantName += ".b2clogin.com";
}
var tokenConfigurationUrl = $"https://{tenantName}/{azureB2cConfig.TenantId}/.well-known/openid-configuration?p={ropcPolicyName}";
var _configManager = new ConfigurationManager<OpenIdConnectConfiguration>(tokenConfigurationUrl, new OpenIdConnectConfigurationRetriever());
var _config = _configManager.GetConfigurationAsync().Result;
Config.Add(portalId, new B2CControllerConfiguration(ropcPolicyName, _config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DotNetNuke.Authentication.Azure.B2C</RootNamespace>
<AssemblyName>DotNetNuke.Authentication.Azure.B2C</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
Expand Down Expand Up @@ -388,7 +388,7 @@
<Error Condition="!Exists('..\DotNetNuke.Authentication.Azure.B2C\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\DotNetNuke.Authentication.Azure\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>IF $(ConfigurationName)==Debug copy $(TargetDir)$(TargetName).* c:\websites\tmh2-admin.dnndev.me\bin /Y</PostBuildEvent>
<PostBuildEvent>IF $(ConfigurationName)==Debug copy $(TargetDir)$(TargetName).* c:\websites\b2c.dnndev.me\bin /Y</PostBuildEvent>
</PropertyGroup>
<Import Project="..\.build\ModulePackage.Targets" />
<Import Project="..\DotNetNuke.Authentication.Azure.B2C\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('..\DotNetNuke.Authentication.Azure.B2C\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]

Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void SaveGeneralSettings(string service, int portalId, AzureADB2CP
{
var config = new AzureConfig(service, portalId)
{
TenantName = settings.TenantName.ToLowerInvariant().Trim().Replace(".onmicrosoft.com", ""),
TenantName = settings.TenantName.ToLowerInvariant().Trim().Replace(".onmicrosoft.com", "").Replace(".b2clogin.com", ""),
TenantId = settings.TenantId,
APIKey = settings.ApiKey,
APISecret = settings.ApiSecret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,22 @@ public HttpResponseMessage AddUser(AddUserParameters parameters)
}
// Ensure user is on this tenant
var identity = newUser.Identities.FirstOrDefault();
identity.Issuer = $"{settings.TenantName}.onmicrosoft.com";
var tenantName = settings.TenantName;
if (!tenantName.Contains("."))
{
tenantName += ".onmicrosoft.com";
}
identity.Issuer = tenantName;

if (bool.Parse(Utils.GetTabModuleSetting(ActiveModule.TabModuleID, "EnableAddUsersByUsername", "False"))
&& !string.IsNullOrEmpty(newUser.UserPrincipalName))
{
AddIdentity(newUser, $"{settings.TenantName}.onmicrosoft.com", "userName", newUser.UserPrincipalName);
AddIdentity(newUser, tenantName, "userName", newUser.UserPrincipalName);
}
if (bool.Parse(Utils.GetTabModuleSetting(ActiveModule.TabModuleID, "EnableAddUsersByEmail", "True"))
&& !string.IsNullOrEmpty(newUser.Mail))
{
AddIdentity(newUser, $"{settings.TenantName}.onmicrosoft.com", "emailAddress", newUser.Mail);
AddIdentity(newUser, tenantName, "emailAddress", newUser.Mail);
newUser.OtherMails = new string[] { newUser.Mail };
}
newUser.PasswordProfile.Password = parameters.passwordType == "auto"
Expand Down Expand Up @@ -331,17 +336,22 @@ public HttpResponseMessage UpdateUser(UpdateUserParameters parameters)
}
else
{
var tenantName = settings.TenantName;
if (!tenantName.Contains("."))
{
tenantName += ".onmicrosoft.com";
}
if (bool.Parse(Utils.GetTabModuleSetting(ActiveModule.TabModuleID, "EnableAddUsersByUsername", "False"))
&& !string.IsNullOrEmpty(parameters.user.Mail)
&& !parameters.user.Mail.Contains("@"))
{
AddIdentity(user, $"{settings.TenantName}.onmicrosoft.com", "userName", parameters.user.Mail);
AddIdentity(user, tenantName, "userName", parameters.user.Mail);
}

if (!string.IsNullOrEmpty(parameters.user.Mail)
&& parameters.user.Mail.Contains("@"))
{
AddIdentity(user, $"{settings.TenantName}.onmicrosoft.com", "emailAddress", parameters.user.Mail);
AddIdentity(user, tenantName, "emailAddress", parameters.user.Mail);
user.OtherMails = new string[] { parameters.user.Mail };
}
}
Expand Down Expand Up @@ -641,7 +651,12 @@ private User GetGraphUserForImpersonation(AzureConfig settings, GraphClient grap
}
else if (idUserMapping.B2cClaimName.ToLowerInvariant() == "emails")
{
user = graphClient.GetAllUsers($"identities/any(c:c/issuer eq '{settings.TenantName}.onmicrosoft.com' and c/issuerAssignedId eq '{usernameWithoutPrefix}')").FirstOrDefault();
var tenantName = settings.TenantName;
if (!tenantName.Contains("."))
{
tenantName += ".onmicrosoft.com";
}
user = graphClient.GetAllUsers($"identities/any(c:c/issuer eq '{tenantName}' and c/issuerAssignedId eq '{usernameWithoutPrefix}')").FirstOrDefault();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<value>Sie müssen den Azure AD B2C-Mandantennamen angeben</value>
</data>
<data name="lblTenantName.Help" xml:space="preserve">
<value>Azure Active Directory B2C-Mandantenname (&amp;lt;TenantName&amp;gt;.onmicrosoft.com). Geben Sie nicht den Teil ".onmicrosoft.com" an, sondern nur den Namen des Mandanten.</value>
<value>Azure Active Directory B2C-Mandantenname (&amp;lt;TenantName&amp;gt;.onmicrosoft.com). Geben Sie nicht den Teil ".onmicrosoft.com" an, sondern nur den Namen des Mandanten. Wenn Sie Azure AD B2C mit einer benutzerdefinierten Domäne verwenden, geben Sie stattdessen Ihre benutzerdefinierte Domäne ein (z. B. login.mydomain.com)</value>
</data>
<data name="lblTenantId.Text" xml:space="preserve">
<value>Mandanten ID</value>
Expand Down Expand Up @@ -500,5 +500,5 @@
</data>
<data name="lblOnErrorUri.Text" xml:space="preserve">
<value>Bei Auth-Fehler Uri</value>
</data>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<value>Debes especificar el nombre del tenant de Azure AD B2C</value>
</data>
<data name="lblTenantName.Help" xml:space="preserve">
<value>El nombre del tenant de Azure Active Directory B2C(&amp;lt;NombreTenant&amp;gt;.onmicrosoft.com). No incluyas la parte ".onmicrosoft.com", simplemente el nombre del tenant</value>
<value>El nombre del tenant de Azure Active Directory B2C(&amp;lt;NombreTenant&amp;gt;.onmicrosoft.com). No incluyas la parte ".onmicrosoft.com", simplemente el nombre del tenant. Si estás usando Azure AD B2C con un dominio personalizado, introduce el nombre del dominio personalizado (ej: login.mydomain.com)</value>
</data>
<data name="lblTenantId.Text" xml:space="preserve">
<value>ID de Tenant</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<value>You must specify the Azure AD B2C Tenant Name</value>
</data>
<data name="lblTenantName.Help" xml:space="preserve">
<value>Azure Active Directory B2C tenant name (&amp;lt;TenantName&amp;gt;.onmicrosoft.com). Don't include the ".onmicrosoft.com" part, just the tenant name</value>
<value>Azure Active Directory B2C tenant name (&amp;lt;TenantName&amp;gt;.onmicrosoft.com). Don't include the ".onmicrosoft.com" part, just the tenant name. If you are using Azure AD B2C with a custom domain, type your custom domain instead (i.e. login.mydomain.com)</value>
</data>
<data name="lblTenantId.Text" xml:space="preserve">
<value>Tenant ID</value>
Expand Down
Loading