public TokenAuthorizationResult GetAccessToken(string username) { var expiresIn = _configurationService.GetSetting <int>("Jwt:AccessTokenExpirationInMinutes"); var jwtKey = _configurationService.GetSetting <string>("Jwt:Key"); var issuer = _configurationService.GetSetting <string>("Jwt:Issuer"); var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); var claims = new[] { new Claim(ClaimsIdentity.DefaultNameClaimType, username), new Claim(JwtRegisteredClaimNames.Email, username), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var token = new JwtSecurityToken( issuer, issuer, claims, expires: DateTime.Now.AddMinutes(expiresIn), signingCredentials: credentials); var result = new JwtSecurityTokenHandler().WriteToken(token); return(new TokenAuthorizationResult(result, expiresIn)); }
public DatabaseEngine GetDatabaseEngine() { string engineConfig = _configurationService.GetSetting <string>("DatabaseSettings:Engine"); return(Enum.TryParse <DatabaseEngine>(engineConfig, ignoreCase: true, out var result) ? result : DatabaseEngine.Postgres); }
private bool IsValidToken(RefreshToken token) { var lifeTime = _configurationService.GetSetting <int>("Jwt:RefreshTokenExpirationInMinutes"); return(token.CreatedAtUtc + TimeSpan.FromMinutes(lifeTime) > DateTime.UtcNow); }