public virtual Jwt CreateJwt(KullaniciParentModel kullanici, JwtOptions jwtOptions) { try { var securityKeyHelper = new SecurityKeyHelper(); var securityKey = securityKeyHelper.CreateSecurityKey(jwtOptions.SecurityKey); var signingCredentialsHelper = new SigningCredentialsHelper(); var signingCredentials = signingCredentialsHelper.CreateSigningCredentials(securityKey); var claimList = new List <Claim>(); claimList.AddUserNameIdentifier(kullanici.Guid); claimList.AddUserName(kullanici.KullaniciAdi); if (kullanici.Rol != null) { claimList.AddRoleNames(new string[] { kullanici.Rol.Adi }); } var expiration = DateTimeUtil.AddTimeToDate(DateTime.Now, 0, jwtOptions.JwtExpirationMinutes); var jwtSecurityToken = new JwtSecurityToken(jwtOptions.Issuer, jwtOptions.Audience, claimList, DateTime.Now, expiration, signingCredentials); var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); var token = jwtSecurityTokenHandler.WriteToken(jwtSecurityToken); var jwt = new Jwt() { Token = token, Expiration = expiration }; return(jwt); } catch (Exception exc) { return(null); } }
public Jwt CreateJwt(KullaniciParentModel kullanici, JwtOptions jwtOptions) { try { var result = _jwtUtil.CreateJwt(kullanici, jwtOptions); return(result); } catch (Exception exc) { return(null); } }