-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated documentation for the new validation model and restructured internals #3056
base: dev
Are you sure you want to change the base?
Conversation
… of GetCurrentStackFrame() and AddCurrentStackFrame()
…fields onto their own files and made the structures read-only.
src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs
Show resolved
Hide resolved
…g IList values from two-part constructors.
… no ActorValidationParameters are provided.
…once the classes/structures are made public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 28 out of 43 changed files in this pull request and generated no comments.
Files not reviewed (15)
- src/Microsoft.IdentityModel.Tokens/InternalAPI.Unshipped.txt: Language not supported
- src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateToken.StackFrames.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SecurityTokenHandler.ValidateToken.StackFrames.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens.Saml/Saml/SamlSecurityTokenHandler.ValidateToken.StackFrames.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/AlgorithmValidationError.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SecurityTokenHandler.ValidateToken.Internal.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/IssuerSigningKeyValidationError.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/AudienceValidationError.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens.Saml/Saml/SamlSecurityTokenHandler.ValidateToken.Internal.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Exceptions/Saml2ValidationError.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/MessageDetail.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.DecryptTokenResult.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.DecryptToken.cs: Evaluated as low risk
- src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ReadToken.cs: Evaluated as low risk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I've asked a few questions, which I'd like to be addressed, and proposed to improve the error messages to make them more actionable.
/// Creates an instance of an <see cref="Exception"/> using <see cref="ValidationError"/> | ||
/// </summary> | ||
/// <returns>An instance of an Exception.</returns> | ||
public override Exception GetException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method is called several times, shouldn't the exception be cached?
/// Creates an instance of an <see cref="Exception"/> using <see cref="ValidationError"/> | ||
/// </summary> | ||
/// <returns>An instance of an Exception.</returns> | ||
public override Exception GetException() | ||
{ | ||
if (ExceptionType == typeof(Saml2SecurityTokenReadException)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question. Don't we want to cache the exception?
/// Creates an instance of an <see cref="Exception"/> using <see cref="ValidationError"/> | ||
/// </summary> | ||
/// <returns>An instance of an Exception.</returns> | ||
public override Exception GetException() | ||
{ | ||
if (ExceptionType == typeof(SecurityTokenInvalidAlgorithmException)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same remark
@@ -28,7 +41,7 @@ public AudienceValidationError( | |||
/// Creates an instance of an <see cref="Exception"/> using <see cref="ValidationError"/> | |||
/// </summary> | |||
/// <returns>An instance of an Exception.</returns> | |||
internal override Exception GetException() | |||
public override Exception GetException() | |||
{ | |||
if (ExceptionType == typeof(SecurityTokenInvalidAudienceException)) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
/// Creates an instance of an <see cref="Exception"/> using <see cref="ValidationError"/> | ||
/// </summary> | ||
/// <returns>An instance of an Exception.</returns> | ||
public override Exception GetException() | ||
{ | ||
if (ExceptionType == typeof(SecurityTokenInvalidSigningKeyException)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same (cache?)
/// <param name="securityToken">The <see cref="SecurityToken"/> that is being validated.</param> | ||
/// <param name="tokenHandler">The <see cref="TokenHandler"/> that is being used to validate the token.</param> | ||
/// <param name="validationParameters">The <see cref="ValidationParameters"/> to be used for validating the token.</param> | ||
internal class ValidatedToken( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ValidatedToken? Or ValidatedTokenResult?
@@ -177,6 +201,9 @@ private object ClaimsIdentitySyncObj | |||
#endregion | |||
|
|||
#region Logging | |||
/// <summary> | |||
/// Internal class used for logging. | |||
/// </summary> | |||
private static class Logger | |||
{ | |||
private static readonly Action<ILogger, string, string, Exception?> s_tokenValidationFailed = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no test against the log level?
@@ -233,8 +213,7 @@ await ValidateJWSAsync(decryptedToken!, validationParameters, configuration, cal | |||
|
|||
if (!validationResult.IsValid) | |||
{ | |||
StackFrame validationFailureStackFrame = StackFrames.JWEValidationFailed ??= new StackFrame(true); | |||
return validationResult.UnwrapError().AddStackFrame(validationFailureStackFrame); | |||
return validationResult.UnwrapError().AddCurrentStackFrame(); | |||
} | |||
|
|||
JsonWebToken jsonWebToken = (validationResult.UnwrapResult().SecurityToken as JsonWebToken)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 248, can we do better (more precise?) than catching the general Exception class?
return ValidationError.NullParameter( | ||
nameof(jwtToken), | ||
tokenNullStackFrame); | ||
ValidationError.GetCurrentStackFrame()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValidationError.GetCurrentStackFrame()); | |
ValidationError.GetCurrentStackFrame(), | |
"The JWT token provided is null. Ensure that a valid token is passed."); |
return ValidationError.NullParameter( | ||
nameof(validationParameters), | ||
validationParametersNullStackFrame); | ||
ValidationError.GetCurrentStackFrame()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValidationError.GetCurrentStackFrame()); | |
ValidationError.GetCurrentStackFrame() | |
"Validation parameters are missing. Provide the necessary parameters for token validation."); |
Updated documentation for the new validation model and restructured internals
Clean up work and documentation updates for the new validation model.
GetCurrentStackFrame()
andAddCurrentStackFrame()
IssuerValidationSource
to be extensible.Part of #2711