public JwtToken GetToken(UserAuthData userAuthData) { if (userAuthData == null) { throw new ArgumentNullException(nameof(userAuthData)); } var jwtConfig = _jwtAuthConfigProvider.GetConfig(); var key = new SymmetricSecurityKey(jwtConfig.Key); var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var claimsModel = JwtClaimsModel.Create(userAuthData); var token = new JwtSecurityToken( jwtConfig.Issuer, jwtConfig.Audience, claimsModel.GetClaims(), expires: DateTime.Now.AddMinutes(5), signingCredentials: credentials); var tokenValue = new JwtSecurityTokenHandler().WriteToken(token); return(new JwtToken(claimsModel.GetTokenId(), tokenValue)); }
public UserInfo GetAuthInfo() { var currentContext = _httpContextProvider.Get(); var currentPrincipal = currentContext.User; if (currentPrincipal == null) { throw new InvalidOperationException("Current user principal is not defined."); } var jwtClaimsModel = JwtClaimsModel.Parse(currentPrincipal); return(jwtClaimsModel.GetUserInfo()); }