public ClaimsPrincipal GetPrincipal(string token) { try { var appKey = ""; using (var dbContext = new PromoDbContext()) { appKey = dbContext.ClientSecrets.FirstOrDefault(cs => cs.AppValue == token)?.AppKey; } var tokenHandler = new JwtSecurityTokenHandler(); if (!(tokenHandler.ReadToken(token) is JwtSecurityToken jwtToken)) { return(null); } var symmetricKey = Convert.FromBase64String(appKey); var validationParameters = new TokenValidationParameters() { RequireExpirationTime = false, ValidateIssuer = false, ValidateLifetime = false, ValidateAudience = false, IssuerSigningKey = new SymmetricSecurityKey(symmetricKey) }; var principal = tokenHandler.ValidateToken(token, validationParameters, out _); return(principal); } catch (Exception exce) { string error = exce.Message; return(null); } }
public PromoController(PromoDbContext context) { _context = context; }
public ClientSecretController(PromoDbContext context, IJwtManager jwtManager) { _context = context; _jwtManager = jwtManager; }