Skip to content

Commit

Permalink
Mark synchronous wrapper as obsolete (#2263)
Browse files Browse the repository at this point in the history
* Mark synchronous wrapper as obsolete

* fix link

* Edit tests to no longer use obsolete method

* Clear up use of obsolete method
  • Loading branch information
westin-m authored Aug 28, 2023
1 parent f470dca commit 9e87d9b
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ public override SecurityToken ReadToken(string token)
/// <param name="token">A 'JSON Web Token' (JWT) in JWS or JWE Compact Serialization Format.</param>
/// <param name="validationParameters">A <see cref="TokenValidationParameters"/> required for validation.</param>
/// <returns>A <see cref="TokenValidationResult"/></returns>
[Obsolete("`JsonWebTokens.ValidateToken(string, TokenValidationParameters)` has been deprecated and will be removed in a future release. Use `JsonWebTokens.ValidateTokenAsync(string, TokenValidationParameters)` instead. For more information, see https://aka.ms/IdentityModel/7-breaking-changes", false)]
public virtual TokenValidationResult ValidateToken(string token, TokenValidationParameters validationParameters)
{
return ValidateTokenAsync(token, validationParameters).ConfigureAwait(false).GetAwaiter().GetResult();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void CreateSignedHttpRequest()
IssuerSigningKey = SignedHttpRequestTestUtils.DefaultSigningCredentials.Key
};

var result = new JsonWebTokenHandler().ValidateToken(signedHttpRequestString, tvp);
var result = new JsonWebTokenHandler().ValidateTokenAsync(signedHttpRequestString, tvp).Result;
if (result.IsValid == false)
context.AddDiff($"Not able to create and validate signed http request token");

Expand Down Expand Up @@ -83,7 +83,7 @@ public void CreateSignedHttpRequestWithAdditionalHeaderClaims()
IssuerSigningKey = SignedHttpRequestTestUtils.DefaultSigningCredentials.Key
};

var result = new JsonWebTokenHandler().ValidateToken(signedHttpRequestString, tvp);
var result = new JsonWebTokenHandler().ValidateTokenAsync(signedHttpRequestString, tvp).Result;

if (result.IsValid == false)
context.AddDiff($"Not able to create and validate signed http request token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ public static TheoryData<ValidateSignedHttpRequestTheoryData> ValidateSignedHttp
var signedHttpRequestWithNullAt = SignedHttpRequestTestUtils.ReplaceOrAddPropertyAndCreateDefaultSignedHttpRequest(new JProperty(SignedHttpRequestClaimTypes.At, null));
var signedHttpRequestWithEmptyAt = SignedHttpRequestTestUtils.ReplaceOrAddPropertyAndCreateDefaultSignedHttpRequest(new JProperty(SignedHttpRequestClaimTypes.At, string.Empty));

var validationResult = new JsonWebTokenHandler().ValidateToken(encodedAccessToken, SignedHttpRequestTestUtils.DefaultTokenValidationParameters);
var validationResult = new JsonWebTokenHandler().ValidateTokenAsync(encodedAccessToken, SignedHttpRequestTestUtils.DefaultTokenValidationParameters).Result;
var resultingClaimsIdentity = validationResult.ClaimsIdentity;
var validatedToken = validationResult.SecurityToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void ValidateTokenShimWithDeprecatedModel(string token)
/// </param>
public void ValidateTokenShim(string token, TokenValidationParameters tokenValidationParameters)
{
var result = JsonWebTokenHandler.ValidateToken(token, tokenValidationParameters);
var result = JsonWebTokenHandler.ValidateTokenAsync(token, tokenValidationParameters).Result;

if (!result.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void SigningKeysExtensibility()
ValidateLifetime = false,
};

var tokenValidationResult = new JsonWebTokens.JsonWebTokenHandler().ValidateToken(Default.AsymmetricJwt, tokenValidationParameters);
var tokenValidationResult = new JsonWebTokens.JsonWebTokenHandler().ValidateTokenAsync(Default.AsymmetricJwt, tokenValidationParameters).Result;

if (tokenValidationResult.IsValid != true)
context.Diffs.Add("tokenValidationResult.IsValid != true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void CreateJweEcdhEsTests(CreateEcdhEsTheoryData theoryData)
string jsonJwe = jsonWebTokenHandler.CreateToken(securityTokenDescriptor);
string jwtJwe = jwtSecurityTokenHandler.CreateEncodedJwt(securityTokenDescriptor);

TokenValidationResult tokenValidationResult1 = jsonWebTokenHandler.ValidateToken(jsonJwe, theoryData.TokenValidationParameters);
TokenValidationResult tokenValidationResult2 = jsonWebTokenHandler.ValidateToken(jwtJwe, theoryData.TokenValidationParameters);
TokenValidationResult tokenValidationResult1 = jsonWebTokenHandler.ValidateTokenAsync(jsonJwe, theoryData.TokenValidationParameters).Result;
TokenValidationResult tokenValidationResult2 = jsonWebTokenHandler.ValidateTokenAsync(jwtJwe, theoryData.TokenValidationParameters).Result;
TokenValidationResult tokenValidationResult3 = jwtSecurityTokenHandler.ValidateTokenAsync(jsonJwe, theoryData.TokenValidationParameters).GetAwaiter().GetResult();
TokenValidationResult tokenValidationResult4 = jwtSecurityTokenHandler.ValidateTokenAsync(jwtJwe, theoryData.TokenValidationParameters).GetAwaiter().GetResult();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void action()
{
var jwt = theoryData.JwtSecurityTokenHandler.CreateEncodedJwt(theoryData.TokenDescriptor);
var claimsPrincipal = theoryData.JwtSecurityTokenHandler.ValidateToken(theoryData.Jwt, theoryData.ValidationParameters, out SecurityToken _);
var tokenValidationResult = theoryData.JsonWebTokenHandler.ValidateToken(theoryData.Jwt, theoryData.ValidationParameters);
var tokenValidationResult = theoryData.JsonWebTokenHandler.ValidateTokenAsync(theoryData.Jwt, theoryData.ValidationParameters).Result;

if (tokenValidationResult.Exception != null && tokenValidationResult.IsValid)
context.Diffs.Add("tokenValidationResult.IsValid, tokenValidationResult.Exception != null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public static TheoryData<JwtSecurityTokenConverterTheoryData> ConverterTheoryDat
IssuerSigningKey = KeyingMaterial.JsonWebKeyRsa256SigningCredentials.Key
};

var result = handler.ValidateToken(jweTokenString, validationParameters);
var result = handler.ValidateTokenAsync(jweTokenString, validationParameters).Result;
var jweToken = result.SecurityToken as JsonWebToken;

result = handler.ValidateToken(jwsTokenString, validationParameters);
result = handler.ValidateTokenAsync(jwsTokenString, validationParameters).Result;
var jwsTokenFromString = result.SecurityToken as JsonWebToken;

var jwsTokenFromHeaderAndPayload = new JsonWebToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ public void CreateJWEUsingSecurityTokenDescriptor(CreateTokenTheoryData theoryDa
string jweFromJsonHandler = theoryData.JsonWebTokenHandler.CreateToken(theoryData.TokenDescriptor);

var claimsPrincipalJwt = theoryData.JwtSecurityTokenHandler.ValidateToken(tokenFromTokenDescriptor, theoryData.ValidationParameters, out SecurityToken validatedTokenFromJwtHandler);
var validationResultJson = theoryData.JsonWebTokenHandler.ValidateToken(jweFromJsonHandler, theoryData.ValidationParameters);
var validationResultJson = theoryData.JsonWebTokenHandler.ValidateTokenAsync(jweFromJsonHandler, theoryData.ValidationParameters).Result;

if (validationResultJson.Exception != null && validationResultJson.IsValid)
context.Diffs.Add("validationResultJson.IsValid, validationResultJson.Exception != null");

IdentityComparer.AreEqual(validationResultJson.IsValid, theoryData.IsValid, context);

var validatedTokenFromJsonHandler = validationResultJson.SecurityToken;
var validationResult2 = theoryData.JsonWebTokenHandler.ValidateToken(tokenFromTokenDescriptor, theoryData.ValidationParameters);
var validationResult2 = theoryData.JsonWebTokenHandler.ValidateTokenAsync(tokenFromTokenDescriptor, theoryData.ValidationParameters).Result;

if (validationResult2.Exception != null && validationResult2.IsValid)
{
Expand Down

0 comments on commit 9e87d9b

Please sign in to comment.