-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ValidateTokenAsync - New Path: Refactor result types (#2794)
* Adding benchmark for new ValidateTokenAsync model vs old. * Update benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithVPTests.cs * Removed IdentityComparer methods relating to removed result types. Updated tests for Algorithm and Audience validation * Removed ITokenValidationError interface. Updated tests * Replaced TokenValidationError with ExceptionDetails. Added stack frames to failures, added initial cache experiment for stack frames * Removed optionality from CancellationToken parameter * Updated tests * Added ClaimsIdentity to ValidationResult * Updated benchmarks to match the result types and added CancellationToken * Removed test consoleapp, re-grouped benchmarks for better comparison * Removed unit type * Removed TokenValidationError since it is no longer used * Restored ExceptionType type name * Restored ExceptionFromType method in ExceptionDetail * Override Result's empty initialiser and annotate it to prevent wrong initialisation * Removed commented code. * Commented empty if statement * Added cached stack frames and nullability annotations for ValidateTokenAsync Changed return type to use Result and removed error information from ValidationResult Added method to add StackFrames to ExceptionDetail * Added stack frames for ReadToken and DecryptToken * Added ValidationFailureType to ExceptionDetail * Updated tests to use ValidationFailureType * Update src/Microsoft.IdentityModel.Abstractions/Result.cs Co-authored-by: Keegan Caruso <[email protected]> * Moved Result to Tokens project, made it internal. Reverted TargetFrameworks change to LoggingExtensions * Addressed PR feedback around argument null exceptions * Addressed PR comments. Removed unused imports. Increased epsilon for datetime comparison in tests. --------- Co-authored-by: Franco Fung <[email protected]> Co-authored-by: Franco Fung <[email protected]> Co-authored-by: Keegan Caruso <[email protected]> Add benchmark to test validation with an issuer delegate using string vs bytes issuer. Add a class with profiler methods.
- Loading branch information
Showing
10 changed files
with
200 additions
and
17 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
benchmark/Microsoft.IdentityModel.Benchmarks/ProfilerRuns.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
public class ProfilerRuns | ||
{ | ||
ReadOnlyMemory<char> _encodedJWSAsMemory; | ||
private JsonWebTokenHandler _jsonWebTokenHandler; | ||
private SecurityTokenDescriptor _tokenDescriptorExtendedClaims; | ||
private string _jwsExtendedClaims; | ||
private TokenValidationParameters _tokenValidationParameters; | ||
|
||
public ProfilerRuns() | ||
{ | ||
var jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
var jwsTokenDescriptor = new SecurityTokenDescriptor | ||
{ | ||
SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256, | ||
TokenType = JwtHeaderParameterNames.Jwk, | ||
Claims = BenchmarkUtils.Claims | ||
}; | ||
|
||
var encodedJWS = jsonWebTokenHandler.CreateToken(jwsTokenDescriptor); | ||
_encodedJWSAsMemory = encodedJWS.AsMemory(); | ||
|
||
_tokenDescriptorExtendedClaims = new SecurityTokenDescriptor | ||
{ | ||
Claims = BenchmarkUtils.ClaimsExtendedExample, | ||
SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256, | ||
}; | ||
|
||
_jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
_jwsExtendedClaims = _jsonWebTokenHandler.CreateToken(_tokenDescriptorExtendedClaims); | ||
|
||
_tokenValidationParameters = new TokenValidationParameters() | ||
{ | ||
ValidAudience = BenchmarkUtils.Audience, | ||
ValidateLifetime = true, | ||
ValidIssuer = BenchmarkUtils.Issuer, | ||
IssuerSigningKey = BenchmarkUtils.SigningCredentialsRsaSha256.Key, | ||
}; | ||
} | ||
|
||
public void ReadJws() | ||
{ | ||
JsonWebToken jwt; | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
jwt = new JsonWebToken(_encodedJWSAsMemory); | ||
} | ||
} | ||
|
||
public async Task ValidateJws() | ||
{ | ||
TokenValidationResult tokenValidationResult; | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
tokenValidationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Microsoft.IdentityModel.Tokens/Validation/Results/ValidationResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.