Skip to content

Commit

Permalink
Move claimextensions;
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteLeon committed Sep 22, 2023
1 parent a6fc01b commit 2dc008a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CleanMicroserviceSystem.Authentication.Configurations;
namespace CleanMicroserviceSystem.Authentication.Domain.Configurations;

public class JwtBearerConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions src/WebUI/CleanMicroserviceSystem.Aphrodite/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2dc008a

Please sign in to comment.