internal override void ProcessToken(string token) { TokenReadResult result = ReadToken(token); if (result.Success) { IConfigurationManager <OpenIdConnectConfiguration> configurationManager = new ConfigurationManager <OpenIdConnectConfiguration>($"{result.Token.Issuer.EnsureTrailingSlash()}.well-known/openid-configuration", new OpenIdConnectConfigurationRetriever()); OpenIdConnectConfiguration openIdConfig = configurationManager.GetConfigurationAsync(CancellationToken.None).Result; TokenValidationParameters validationParameters = new TokenValidationParameters { ValidIssuers = _issuers.Values, ValidAudiences = _audiences.Values, IssuerSigningKeys = openIdConfig.SigningKeys, ValidateLifetime = _lifetime.HasValue() }; SecurityToken validatedToken; JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler(); try { var user = handler.ValidateToken(token, validationParameters, out validatedToken); Logger.LogInformation("token is valid"); } catch (Exception ex) { throw new CommandException(ex.Message); } } else { Logger.LogError(new EventId(), result.Exception, "the token is invalid"); } }
internal override void ProcessToken(string token) { TokenReadResult result = ReadToken(token); if (result.Success) { Logger.LogInformation(result.Token.ToString()); } else { Logger.LogError(new EventId(), result.Exception, "the token is invalid"); } }
protected static TokenReadResult ReadToken(string encodedToken) { TokenReadResult result = new TokenReadResult(); try { var tokenHandler = new JwtSecurityTokenHandler(); result.Token = tokenHandler.ReadJwtToken(encodedToken); result.Success = true; } catch (Exception ex) { result.Exception = ex; } return(result); }