< Summary

Information
Class: Syki.Back.Configs.AuthenticationConfigs
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Configs/AuthenticationConfigs.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 46
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddAuthenticationConfigs(...)100%11100%

File(s)

/home/runner/work/syki/syki/Back/Configs/AuthenticationConfigs.cs

#LineLine coverage
 1using System.Text;
 2using Microsoft.IdentityModel.Tokens;
 3using System.IdentityModel.Tokens.Jwt;
 4
 5namespace Syki.Back.Configs;
 6
 7public static class AuthenticationConfigs
 8{
 9    public const string BearerScheme = "Bearer";
 10
 11    public static void AddAuthenticationConfigs(this IServiceCollection services)
 12    {
 113        using var serviceProvider = services.BuildServiceProvider();
 114        var settings = serviceProvider.GetService<AuthSettings>()!;
 15
 116        JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
 117        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
 18
 119        var tokenValidationParameters = new TokenValidationParameters
 120        {
 121            ValidateIssuer = true,
 122            ValidIssuer = settings.Issuer,
 123
 124            ValidateIssuerSigningKey = true,
 125            IssuerSigningKey = new SymmetricSecurityKey(
 126                Encoding.ASCII.GetBytes(settings.SecurityKey)
 127            ),
 128
 129            ValidAlgorithms = [ "HS256" ],
 130
 131            ValidateAudience = true,
 132            ValidAudience = settings.Audience,
 133
 134            ValidateLifetime = true,
 135            ClockSkew = TimeSpan.Zero,
 136
 137            RoleClaimType = "role",
 138        };
 39
 140        services.AddAuthentication(BearerScheme)
 141            .AddJwtBearer(BearerScheme, options =>
 142            {
 143                options.TokenValidationParameters = tokenValidationParameters;
 244            });
 245    }
 46}