/// <summary>Try to validate the token header, according to the <paramref name="header"/>.</summary> /// <returns><c>true</c> if the <paramref name="header"/> is valid. <c>false</c> otherwise.</returns> public bool TryValidateHeader(JwtHeaderDocument header, [NotNullWhen(false)] out TokenValidationError?error) { if (!IgnoreCriticalHeader) { if (!header.Crit.IsEmpty) { var handlers = CriticalHandlers; foreach (var critHeader in header.Crit.EnumerateArray <string>()) { var critHeaderName = critHeader.GetString() !; if (!handlers.TryGetValue(critHeaderName, out var handler)) { error = TokenValidationError.CriticalHeaderUnsupported(critHeaderName); goto Error; } if (!handler.TryHandle(header, critHeaderName)) { error = TokenValidationError.InvalidHeader(critHeaderName); goto Error; } } } } error = null; return(true); Error: return(false); }