Skip to content

Commit c8f7d87

Browse files
brentschmaltzHP712
andauthored
Switch to back to ValidationResult for results when validating a token. (#3299)
* OpertionResult -> ValidationResult Remove dependency on Microsoft.Identity.Abstractions * remove dependency --------- Co-authored-by: id4s <[email protected]>
1 parent 1badce8 commit c8f7d87

File tree

59 files changed

+587
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+587
-519
lines changed

benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncTests.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Threading.Tasks;
1010
using BenchmarkDotNet.Attributes;
1111
using BenchmarkDotNet.Configs;
12-
using Microsoft.Identity.Abstractions;
1312
using Microsoft.IdentityModel.JsonWebTokens;
1413
using Microsoft.IdentityModel.Tokens;
1514
using Microsoft.IdentityModel.Tokens.Experimental;
@@ -106,8 +105,8 @@ public async Task<bool> JsonWebTokenHandler_ValidateTokenAsyncWithVP()
106105
{
107106
// Because ValidationResult is an internal type, we cannot return it in the benchmark.
108107
// We return a boolean instead until the type is made public.
109-
OperationResult<ValidatedToken, ValidationError> operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
110-
return operationResult.Succeeded;
108+
ValidationResult<ValidatedToken, ValidationError> validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
109+
return validationResult.Succeeded;
111110
}
112111

113112
[BenchmarkCategory("ValidateTokenAsync_FailTwiceBeforeSuccess"), Benchmark(Baseline = true)]
@@ -133,11 +132,11 @@ public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncW
133132
[BenchmarkCategory("ValidateTokenAsync_FailTwiceBeforeSuccess"), Benchmark]
134133
public async Task<bool> JsonWebTokenHandler_ValidateTokenAsyncWithVP_SucceedOnThirdAttempt()
135134
{
136-
OperationResult<ValidatedToken, ValidationError> operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
137-
operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
138-
operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
135+
ValidationResult<ValidatedToken, ValidationError> validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
136+
validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
137+
validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
139138

140-
return operationResult.Succeeded;
139+
return validationResult.Succeeded;
141140
}
142141

143142
[BenchmarkCategory("ValidateTokenAsync_FailFourTimesBeforeSuccess"), Benchmark(Baseline = true)]
@@ -167,13 +166,13 @@ public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncW
167166
[BenchmarkCategory("ValidateTokenAsync_FailFourTimesBeforeSuccess"), Benchmark]
168167
public async Task<bool> JsonWebTokenHandler_ValidateTokenAsyncWithVP_SucceedOnFifthAttempt()
169168
{
170-
OperationResult<ValidatedToken, ValidationError> operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
171-
operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
172-
operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
173-
operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
174-
operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
169+
ValidationResult<ValidatedToken, ValidationError> validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
170+
validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
171+
validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
172+
validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _invalidValidationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
173+
validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
175174

176-
return operationResult.Succeeded;
175+
return validationResult.Succeeded;
177176
}
178177

179178
[BenchmarkCategory("ValidateTokenAsyncClaimAccess"), Benchmark(Baseline = true)]
@@ -188,8 +187,8 @@ public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithTVP_Cre
188187
[BenchmarkCategory("ValidateTokenAsyncClaimAccess"), Benchmark]
189188
public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithVP_CreateClaims()
190189
{
191-
OperationResult<ValidatedToken, ValidationError> operationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
192-
var claimsIdentity = operationResult.Result.ClaimsIdentity;
190+
ValidationResult<ValidatedToken, ValidationError> validationResult = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, CancellationToken.None).ConfigureAwait(false);
191+
var claimsIdentity = validationResult.Result.ClaimsIdentity;
193192
var claims = claimsIdentity.Claims;
194193
return claims.ToList();
195194
}

build/dependencies.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<AspNetCoreMinSupportedVersion>2.1.1</AspNetCoreMinSupportedVersion>
55
<BannedApiAnalyzersVersion>4.14.0</BannedApiAnalyzersVersion>
6-
<MicrosoftIdentityAbstractionsVersion>9.3.0</MicrosoftIdentityAbstractionsVersion>
76
<MicrosoftBclTimeProviderVersion>8.0.1</MicrosoftBclTimeProviderVersion>
87
<MicrosoftCSharpVersion>4.5.0</MicrosoftCSharpVersion>
98
<MicrosoftSourceLinkGitHubVersion>1.0.0</MicrosoftSourceLinkGitHubVersion>

src/Microsoft.IdentityModel.JsonWebTokens/Experimental/JsonWebTokenHandler.DecryptToken.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Text;
8-
using Microsoft.Identity.Abstractions;
98
using Microsoft.IdentityModel.Logging;
109
using Microsoft.IdentityModel.Tokens;
1110
using Microsoft.IdentityModel.Tokens.Experimental;
@@ -23,8 +22,8 @@ public partial class JsonWebTokenHandler : TokenHandler
2322
/// <param name="validationParameters">The <see cref="TokenValidationParameters"/> to be used for validating the token.</param>
2423
/// <param name="configuration">The <see cref="BaseConfiguration"/> to be used for validating the token.</param>
2524
/// <param name="callContext">A <see cref="CallContext"/> that contains call information.</param>
26-
/// <returns>An <see cref="OperationResult{TResult, TError}"/> with OperationResult.Result containing the clear text or a <see cref="ValidationError"/>.</returns>
27-
internal OperationResult<string, ValidationError> DecryptToken(
25+
/// <returns>An <see cref="ValidationResult{TResult, TError}"/> with ValidationResult.Result containing the clear text or a <see cref="ValidationError"/>.</returns>
26+
internal ValidationResult<string, ValidationError> DecryptToken(
2827
JsonWebToken jwtToken,
2928
ValidationParameters validationParameters,
3029
BaseConfiguration? configuration,

src/Microsoft.IdentityModel.JsonWebTokens/Experimental/JsonWebTokenHandler.ReadToken.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using Microsoft.Identity.Abstractions;
65
using Microsoft.IdentityModel.Tokens;
76
using Microsoft.IdentityModel.Tokens.Experimental;
87

@@ -13,12 +12,12 @@ namespace Microsoft.IdentityModel.JsonWebTokens
1312
public partial class JsonWebTokenHandler : TokenHandler
1413
{
1514
/// <summary>
16-
/// Converts a string into an instance of <see cref="JsonWebToken"/>, returned inside of a <see cref="OperationResult{SecurityToken, ValidationError}"/>.
15+
/// Converts a string into an instance of <see cref="JsonWebToken"/>, returned inside of a <see cref="ValidationResult{SecurityToken, ValidationError}"/>.
1716
/// </summary>
1817
/// <param name="token">A JSON Web Token (JWT) in JWS or JWE Compact Serialization format.</param>
1918
/// <param name="callContext"></param>
20-
/// <returns>A <see cref="OperationResult{SecurityToken, ValidationError}"/> with the <see cref="JsonWebToken"/> or a <see cref="ValidationError"/>.</returns>
21-
internal static OperationResult<SecurityToken, ValidationError> ReadToken(
19+
/// <returns>A <see cref="ValidationResult{SecurityToken, ValidationError}"/> with the <see cref="JsonWebToken"/> or a <see cref="ValidationError"/>.</returns>
20+
internal static ValidationResult<SecurityToken, ValidationError> ReadToken(
2221
string token,
2322
#pragma warning disable CA1801 // TODO: remove pragma disable once callContext is used for logging
2423
CallContext? callContext)

src/Microsoft.IdentityModel.JsonWebTokens/Experimental/JsonWebTokenHandler.ValidateSignature.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Text;
7-
using Microsoft.Identity.Abstractions;
87
using Microsoft.IdentityModel.Logging;
98
using Microsoft.IdentityModel.Tokens;
109
using Microsoft.IdentityModel.Tokens.Experimental;
@@ -23,8 +22,8 @@ public partial class JsonWebTokenHandler : TokenHandler
2322
/// <param name="validationParameters">The parameters used for validation.</param>
2423
/// <param name="configuration">The optional configuration used for validation.</param>
2524
/// <param name="callContext">The context in which the method is called.</param>
26-
/// <returns>A <see cref="OperationResult{SecurityKey, ValidationError}"/> with the <see cref="SecurityKey"/> that signed the tokenif valid or a <see cref="ValidationError"/>.</returns>
27-
internal static OperationResult<SecurityKey, ValidationError> ValidateSignature(
25+
/// <returns>A <see cref="ValidationResult{SecurityKey, ValidationError}"/> with the <see cref="SecurityKey"/> that signed the tokenif valid or a <see cref="ValidationError"/>.</returns>
26+
internal static ValidationResult<SecurityKey, ValidationError> ValidateSignature(
2827
JsonWebToken jwtToken,
2928
ValidationParameters validationParameters,
3029
BaseConfiguration? configuration,
@@ -45,7 +44,7 @@ internal static OperationResult<SecurityKey, ValidationError> ValidateSignature(
4544
{
4645
try
4746
{
48-
OperationResult<SecurityKey, ValidationError> signatureValidationResult =
47+
ValidationResult<SecurityKey, ValidationError> signatureValidationResult =
4948
validationParameters.SignatureValidator(
5049
jwtToken,
5150
validationParameters,
@@ -127,7 +126,7 @@ internal static OperationResult<SecurityKey, ValidationError> ValidateSignature(
127126
ValidationError.GetCurrentStackFrame());
128127
}
129128

130-
private static OperationResult<SecurityKey, ValidationError> ValidateSignatureUsingAllKeys(
129+
private static ValidationResult<SecurityKey, ValidationError> ValidateSignatureUsingAllKeys(
131130
JsonWebToken jwtToken,
132131
ValidationParameters validationParameters,
133132
BaseConfiguration? configuration,
@@ -148,7 +147,7 @@ private static OperationResult<SecurityKey, ValidationError> ValidateSignatureUs
148147
keysTried = true;
149148

150149
// Validate the signature with each key.
151-
OperationResult<SecurityKey, ValidationError> result = ValidateSignatureWithKey(
150+
ValidationResult<SecurityKey, ValidationError> result = ValidateSignatureWithKey(
152151
jwtToken,
153152
validationParameters,
154153
key,
@@ -219,7 +218,7 @@ private static OperationResult<SecurityKey, ValidationError> ValidateSignatureUs
219218
ValidationError.GetCurrentStackFrame());
220219
}
221220

222-
private static OperationResult<SecurityKey, ValidationError> ValidateSignatureWithKey(
221+
private static ValidationResult<SecurityKey, ValidationError> ValidateSignatureWithKey(
223222
JsonWebToken jsonWebToken,
224223
ValidationParameters validationParameters,
225224
SecurityKey key,

0 commit comments

Comments
 (0)