public bool TryValidate(JwtHeaderDocument header, JwtPayloadDocument payload, [NotNullWhen(false)] out TokenValidationError?error) { if (!payload.TryGetClaim(JwtClaimNames.Exp.EncodedUtf8Bytes, out var expires)) { error = TokenValidationError.MissingClaim(JwtClaimNames.Exp.ToString()); return(false); } if (!payload.TryGetClaim(JwtClaimNames.Jti.EncodedUtf8Bytes, out var jti)) { error = TokenValidationError.MissingClaim(JwtClaimNames.Jti.ToString()); return(false); } if (!_tokenReplayCache.TryAdd(jti.GetString(), expires.GetInt64())) { error = TokenValidationError.TokenReplayed(); return(false); } #if NET5_0_OR_GREATER Unsafe.SkipInit(out error); #else error = default; #endif return(true); }
public bool TryValidate(JwtHeaderDocument header, JwtPayloadDocument payload, [NotNullWhen(false)] out TokenValidationError?error) { if (payload is null) { error = TokenValidationError.MalformedToken(); return(false); } if (!payload.TryGetClaim(_claim, out var claim)) { error = TokenValidationError.MissingClaim(_claim); return(false); } if (!claim.TryGetDouble(out var value) || _value != value) { error = TokenValidationError.InvalidClaim(_claim); return(false); } #if NET5_0_OR_GREATER Unsafe.SkipInit(out error); #else error = default; #endif return(true); }
public bool TryValidate(JwtHeaderDocument header, JwtPayloadDocument payload, [NotNullWhen(false)] out TokenValidationError?error) { if (!payload.TryGetClaim(JwtClaimNames.Exp.EncodedUtf8Bytes, out var expires)) { error = TokenValidationError.MissingClaim(JwtClaimNames.Exp.ToString()); return(false); } if (!payload.TryGetClaim(JwtClaimNames.Jti.EncodedUtf8Bytes, out var jti)) { error = TokenValidationError.MissingClaim(JwtClaimNames.Jti.ToString()); return(false); } if (!_tokenReplayCache.TryAdd(jti.GetString(), expires.GetInt64())) { error = TokenValidationError.TokenReplayed(); return(false); } error = null; return(true); }
public bool TryValidate(JwtHeaderDocument header, JwtPayloadDocument payload, [NotNullWhen(false)] out TokenValidationError?error) { if (payload is null) { error = TokenValidationError.MalformedToken(); return(false); } if (!payload.TryGetClaim(_claim, out var claim)) { error = TokenValidationError.MissingClaim(_claim); return(false); } if (!claim.TryGetDouble(out var value) || _value != value) { error = TokenValidationError.InvalidClaim(_claim); return(false); } error = null; return(true); }
public bool TryValidate(JwtHeaderDocument header, JwtPayloadDocument payload, [NotNullWhen(false)] out TokenValidationError?error) { if (payload is null) { error = TokenValidationError.MalformedToken(); return(false); } if (!payload.TryGetClaim(OAuth2Claims.Acr.EncodedUtf8Bytes, out var property)) { error = TokenValidationError.MissingClaim(OAuth2Claims.Acr.ToString()); return(false); } if (!property.ValueEquals(_requiredAcr)) { error = TokenValidationError.InvalidClaim(OAuth2Claims.Acr.ToString()); return(false); } error = null; return(true); }