public async Task <Token> Parse(string token, string issuer, string audience, bool validateSignature) { using (Logger.BeginScope(nameof(Parse))) { try { Validator.ValidateFormat(token, Settings.MaxTokenSize); var jws = ParseJws(token); Validator.ValidateJoseHeader(jws); var payloadClaims = Base64Url.DeserializeData(jws.Parts[1], "JWT payload"); var payload = new TokenPayload(payloadClaims); Validator.ValidatePayload(payload, issuer, audience, Settings.ClockSkew); if (validateSignature) { await Validator.ValidateSignature(jws); } return(new Token { Algorithm = jws.Algorithm, Header = jws.Header, Payload = payload }); } catch (Exception ex) { throw Logger.Exception($"Error parsing the Json Web Token: {ex.Message}"); } } }