< Summary - Syki

Information
Class: Syki.Back.Features.Cross.LoginMfa.LoginMfaService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Cross/LoginMfa/LoginMfaService.cs
Tag: 21_17346963026
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 31
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
LoginMfa()100%22100%

File(s)

/home/runner/work/syki/syki/Back/Features/Cross/LoginMfa/LoginMfaService.cs

#LineLine coverage
 1using System.IdentityModel.Tokens.Jwt;
 2using Syki.Back.Features.Cross.CreateUser;
 3using Syki.Back.Features.Cross.GenerateJWT;
 4
 5namespace Syki.Back.Features.Cross.LoginMfa;
 6
 67public class LoginMfaService(GenerateJWTService service, SignInManager<SykiUser> signInManager) : ICrossService
 8{
 9    public async Task<OneOf<LoginMfaOut, SykiError>> LoginMfa(LoginMfaIn data)
 10    {
 611        var token = data.Token!.OnlyNumbers();
 612        var result = await signInManager.TwoFactorAuthenticatorSignInAsync(token, false, false);
 13
 614        if (!result.Succeeded)
 415            return new LoginWrongMfaToken();
 16
 217        var user = await signInManager.GetTwoFactorAuthenticationUserAsync();
 18
 219        var jwt = await service.Generate(user!.Email!);
 220        var claims = new JwtSecurityToken(jwt).Claims.ToList();
 21
 222        return new LoginMfaOut
 223        {
 224            AccessToken = jwt,
 825            Name = claims.First(x => x.Type == "name").Value,
 1026            Email = claims.First(x => x.Type == "email").Value,
 427            Id = Guid.Parse(claims.First(x => x.Type == "sub").Value),
 628            Role = Enum.Parse<UserRole>(claims.First(x => x.Type == "role").Value),
 229        };
 630    }
 31}