public ClientTokenDto CreateToken(Client client) { var AccesTokenOmru = DateTime.Now.AddMinutes(_customTokenOptions.AccesTokenO); var SecuritKey = SignService.SimetrikAnahtar(_customTokenOptions.SecuritKey); SigningCredentials signingCredentials = new SigningCredentials(SecuritKey, SecurityAlgorithms.HmacSha256Signature); JwtSecurityToken jwtSecurityToken = new JwtSecurityToken( issuer: _customTokenOptions.Issuer, expires: AccesTokenOmru, notBefore: DateTime.Now, claims: GetClaimsByClient(client), signingCredentials: signingCredentials); var handler = new JwtSecurityTokenHandler(); var token = handler.WriteToken(jwtSecurityToken); var tokenDto = new ClientTokenDto { AccessToken = token, AccessTokenExpiration = AccesTokenOmru, }; return(tokenDto); }
public TokenDto CreateToken(Kullanici kullanici) { var AccesTokenOmru = DateTime.Now.AddMinutes(_customTokenOptions.AccesTokenO); var RefreshTokenOmru = DateTime.Now.AddMinutes(_customTokenOptions.RefreshTokenO); var SecuritKey = SignService.SimetrikAnahtar(_customTokenOptions.SecuritKey); SigningCredentials signingCredentials = new SigningCredentials(SecuritKey, SecurityAlgorithms.HmacSha256Signature); JwtSecurityToken jwtSecurityToken = new JwtSecurityToken( issuer: _customTokenOptions.Issuer, expires: AccesTokenOmru, notBefore: DateTime.Now, claims: GetClaim(kullanici, _customTokenOptions.Audience), signingCredentials: signingCredentials); var handler = new JwtSecurityTokenHandler(); var token = handler.WriteToken(jwtSecurityToken); var tokenDto = new TokenDto { AccessToken = token, RefreshToken = CreateRefreshToken(), AccessTokenExpiration = AccesTokenOmru, RefreshTokenExpiration = RefreshTokenOmru }; return(tokenDto); }