diff --git a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Configurations/JwtBearerConfiguration.cs b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Configurations/JwtBearerConfiguration.cs index 0f63cbdb..3552ffd7 100644 --- a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Configurations/JwtBearerConfiguration.cs +++ b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Configurations/JwtBearerConfiguration.cs @@ -1,4 +1,4 @@ -namespace CleanMicroserviceSystem.Authentication.Configurations; +namespace CleanMicroserviceSystem.Authentication.Domain.Configurations; public class JwtBearerConfiguration { diff --git a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Extensions/ClaimsExtension.cs b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Extensions/ClaimsExtension.cs new file mode 100644 index 00000000..48f7ca1f --- /dev/null +++ b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication.Domain/Extensions/ClaimsExtension.cs @@ -0,0 +1,23 @@ +using System.Security.Claims; + +namespace CleanMicroserviceSystem.Authentication.Domain.Extensions; + +public static class ClaimsExtension +{ + public static int? GetNameIdentifier(this ClaimsIdentity identity) + { + var value = identity?.Claims?.FirstOrDefault(claim => string.Equals(claim.Type, ClaimTypes.NameIdentifier, StringComparison.OrdinalIgnoreCase))?.Value; + if (string.IsNullOrEmpty(value)) return default; + return int.TryParse(value, out var identifier) ? identifier : default; + } + + public static string? GetPhone(this ClaimsIdentity identity) + { + return identity?.Claims?.FirstOrDefault(claim => string.Equals(claim.Type, ClaimTypes.HomePhone, StringComparison.OrdinalIgnoreCase))?.Value; + } + + public static string? GetEmail(this ClaimsIdentity identity) + { + return identity?.Claims?.FirstOrDefault(claim => string.Equals(claim.Type, ClaimTypes.Email, StringComparison.OrdinalIgnoreCase))?.Value; + } +} diff --git a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Extensions/CleanMicroserviceSystemAuthenticationExtension.cs b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Extensions/CleanMicroserviceSystemAuthenticationExtension.cs index d97b9a7b..f166de0f 100644 --- a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Extensions/CleanMicroserviceSystemAuthenticationExtension.cs +++ b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Extensions/CleanMicroserviceSystemAuthenticationExtension.cs @@ -2,6 +2,7 @@ using CleanMicroserviceSystem.Authentication.Application; using CleanMicroserviceSystem.Authentication.Configurations; using CleanMicroserviceSystem.Authentication.Domain; +using CleanMicroserviceSystem.Authentication.Domain.Configurations; using CleanMicroserviceSystem.Authentication.Services; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; diff --git a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Services/JwtBearerTokenGenerator.cs b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Services/JwtBearerTokenGenerator.cs index 6888b08c..b40e2b38 100644 --- a/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Services/JwtBearerTokenGenerator.cs +++ b/src/CommonLibrary/Authentication/CleanMicroserviceSystem.Authentication/Services/JwtBearerTokenGenerator.cs @@ -2,7 +2,7 @@ using System.Security.Claims; using System.Text; using CleanMicroserviceSystem.Authentication.Application; -using CleanMicroserviceSystem.Authentication.Configurations; +using CleanMicroserviceSystem.Authentication.Domain.Configurations; using Microsoft.IdentityModel.Tokens; namespace CleanMicroserviceSystem.Authentication.Services; diff --git a/src/WebUI/CleanMicroserviceSystem.Aphrodite.Application/Extensions/ClaimsExtension.cs b/src/WebUI/CleanMicroserviceSystem.Aphrodite.Application/Extensions/ClaimsExtension.cs deleted file mode 100644 index 9db643c6..00000000 --- a/src/WebUI/CleanMicroserviceSystem.Aphrodite.Application/Extensions/ClaimsExtension.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Security.Claims; - -namespace CleanMicroserviceSystem.Aphrodite.Application.Extensions; - -public static class ClaimsExtension -{ - public static int? GetNameIdentifier(this ClaimsIdentity identity) - { - var value = identity?.Claims.FirstOrDefault(claim => string.Equals(claim.Type, ClaimTypes.NameIdentifier, StringComparison.OrdinalIgnoreCase))?.Value; - if (string.IsNullOrEmpty(value)) return default; - return int.TryParse(value, out int identifier) ? identifier : default; - } - - public static string? GetPhone(this ClaimsIdentity identity) - { - return identity?.Claims.FirstOrDefault(claim => string.Equals(claim.Type, ClaimTypes.HomePhone, StringComparison.OrdinalIgnoreCase))?.Value; - } - - public static string? GetEmail(this ClaimsIdentity identity) - { - return identity?.Claims.FirstOrDefault(claim => string.Equals(claim.Type, ClaimTypes.Email, StringComparison.OrdinalIgnoreCase))?.Value; - } -} diff --git a/src/WebUI/CleanMicroserviceSystem.Aphrodite/_Imports.razor b/src/WebUI/CleanMicroserviceSystem.Aphrodite/_Imports.razor index 3df230b6..908025a8 100644 --- a/src/WebUI/CleanMicroserviceSystem.Aphrodite/_Imports.razor +++ b/src/WebUI/CleanMicroserviceSystem.Aphrodite/_Imports.razor @@ -31,6 +31,7 @@ @using CleanMicroserviceSystem.Astra.Contract.NuGetPackages; @using CleanMicroserviceSystem.Authentication.Application; @using CleanMicroserviceSystem.Authentication.Domain; +@using CleanMicroserviceSystem.Authentication.Domain.Extensions; @using CleanMicroserviceSystem.DataStructure; @using CleanMicroserviceSystem.Themis.Client; @using CleanMicroserviceSystem.Themis.Contract.Roles;