Skip to content
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

ValidateTokenAsync: New code path #2771

Merged
merged 5 commits into from
Aug 13, 2024
Merged

ValidateTokenAsync: New code path #2771

merged 5 commits into from
Aug 13, 2024

Conversation

iNinja
Copy link
Contributor

@iNinja iNinja commented Aug 7, 2024

ValidateTokenAsync: New code path

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • If any gains or losses in performance are possible, you've included benchmarks for your changes. More info
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Join all the refactored validators into a new ValidateTokenAsync entry point.

Description

  • Implementation of ValidateTokenAsync, ValidateJWSAsync, ValidateJWEAsync
  • Added InternalTokenValidationResult to hold the intermediate validation results. Moved result types to their own folder.
  • Removed unused delegate from TokenValidationParameters

Tests to be added before marking ready for review.
Creation of ClaimsIdentity still needs a resolution, as the current implementation in TokenValidationResult uses TokenValidationParameters.

Part of #2711

…ateJWEAsync

Added InternalTokenValidationResult to hold the intermediate validation results. Moved result types to their own folder.
Removed unused delegate from TokenValidationParameters
@iNinja iNinja marked this pull request as ready for review August 12, 2024 17:06
@iNinja iNinja requested a review from a team as a code owner August 12, 2024 17:06
string token,
ValidationParameters validationParameters,
CallContext callContext,
CancellationToken? cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we allow this to be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I have kept it optional and assigned CancellationToken.None if it is not present.
We can make this mandatory over the next weeks if we think it is worth enforcing.

return new TokenValidationResult { Exception = LogHelper.LogArgumentNullException(nameof(validationParameters)), IsValid = false };

if (token.Length > MaximumTokenSizeInBytes)
return new TokenValidationResult { Exception = LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(TokenLogMessages.IDX10209, LogHelper.MarkAsNonPII(token.Length), LogHelper.MarkAsNonPII(MaximumTokenSizeInBytes)))), IsValid = false };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please stack these parameters.

/// <exception cref="ArgumentNullException"></exception>
public InternalTokenValidationResult(SecurityToken? securityToken, TokenHandler tokenHandler)
{
_securityToken = securityToken;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should securityToken be allowed to be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are cases such as validating a token from a string where the reading / decrypting can fail and we end up without a security token, and yet we need to return a result to indicate what went wrong.

Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this committed and then start writing tests and E2E developer experiences.

@iNinja iNinja merged commit 68ff8df into dev Aug 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants