Skip to content

Commit

Permalink
Improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyDevelopment committed Nov 24, 2023
1 parent 9b9fa8b commit b8d6634
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ internal static void AddGatewayAuthentication(IServiceCollection services, Gatew

if (!string.IsNullOrWhiteSpace(tokenSessionId) && context.Principal != null)
{
var sessionIdClaim = new Claim("TokenSessionId", tokenSessionId);
var uniqueNameClaim = context.Principal.Claims.Single(c => c.Type == settings.UniqueIdentifierClaimType);
Claim sessionIdClaim = new Claim("TokenSessionId", tokenSessionId);
Claim? uniqueNameClaim = context.Principal.Claims.SingleOrDefault(c => c.Type == settings.UniqueIdentifierClaimType);

if(uniqueNameClaim == null)
{
ILogger logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<GatewayAuthentication>>();
logger.LogError($"No claim was found with the specified unique identifier type '{settings.UniqueIdentifierClaimType}'");
throw new Exception($"No claim was found with the specified unique identifier type '{settings.UniqueIdentifierClaimType}'");
}

// Setup a new default identity which only contians the token session id
context.Principal = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { sessionIdClaim, uniqueNameClaim }, context.Principal?.Identity?.AuthenticationType, settings.UniqueIdentifierClaimType, null));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.0.5</Version>
<Version>0.0.5-local</Version>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down

0 comments on commit b8d6634

Please sign in to comment.