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

[Bug] Method not found Exception when reading JWT token (Base64UrlEncoder.UnsafeDecode) #2577

Open
JFFby opened this issue May 1, 2024 · 3 comments
Labels
Bug Product is not functioning as expected P1 More important, prioritize highly Regression

Comments

@JFFby
Copy link

JFFby commented May 1, 2024

Which version of Microsoft.IdentityModel are you using?
7.5.1

Where is the issue?

  • M.IM.JsonWebTokens

Is this a new or an existing app?

Repro

I am just trying to add JWT authentication to the existed app

services.AddAuthentication()
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
    options.Audience = apiName;
    options.Authority = identityServerUrl;
});

Expected behavior
Acess token successfully validated

Actual behavior
A clear and concise description of what happens, e.g. an exception is thrown, UI freezes.

Possible solution
I am getting exception:

IDX14100: JWT is not well formed, there are no dots (.).
The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EndcodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'.

Which has inner one with message:

Method not found: 'Byte[] Microsoft.IdentityModel.Tokens.Base64UrlEncoder.UnsafeDecode(System.ReadOnlyMemory`1<Char>)'.

With call stack:

   at Microsoft.IdentityModel.JsonWebTokens.JsonWebToken.ReadToken(String encodedJson)
   at Microsoft.IdentityModel.JsonWebTokens.JsonWebToken..ctor(String jwtEncodedString)
   at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ReadToken(String token, TokenValidationParameters validationParameters)

Additional context / logs / screenshots / links to code

I double checked all dependencies, and they look good for me.

   [net8.0]:
   Top-level Package                                      Requested   Resolved
   > Microsoft.AspNetCore.Authentication.JwtBearer        8.0.4       8.0.4
   > Microsoft.Extensions.DependencyInjection             8.0.0       8.0.0
   > Microsoft.IdentityModel.JsonWebTokens                7.5.1       7.5.1
   > Microsoft.IdentityModel.Protocols.OpenIdConnect      7.5.1       7.5.1
   > Microsoft.IdentityModel.Tokens                       7.5.1       7.5.1
   > OpenIddict.Abstractions                              5.5.0       5.5.0
   > StyleCop.Analyzers                                   1.1.118     1.1.118
   > System.IdentityModel.Tokens.Jwt                      7.5.1       7.5.1

   Transitive Package                                           Resolved
   > Microsoft.Extensions.DependencyInjection.Abstractions      8.0.1
   > Microsoft.Extensions.Primitives                            8.0.0
   > Microsoft.IdentityModel.Abstractions                       7.5.1
   > Microsoft.IdentityModel.Logging                            7.5.1
   > Microsoft.IdentityModel.Protocols                          7.5.1
@JFFby JFFby changed the title [Bug] Method not found Exception May 1, 2024
@JFFby JFFby changed the title Method not found Exception Method not found Exception when reading JWT token May 1, 2024
@pmaytak pmaytak changed the title Method not found Exception when reading JWT token [Bug] Method not found Exception when reading JWT token (Base64UrlEncoder.UnsafeDecode) May 2, 2024
@pmaytak pmaytak added P1 More important, prioritize highly Bug Product is not functioning as expected Regression labels May 2, 2024
@pmaytak
Copy link
Contributor

pmaytak commented May 2, 2024

@JFFby Does that dependency list include transitive packages?

dotnet list yourcsrpoj.csproj package --include-transitive

Can you provide the full call stack?

This may be related to #2504 but that method was internal.

@JFFby
Copy link
Author

JFFby commented May 3, 2024

Hey @pmaytak,
Yes, this list includes transitive packages and this is the full call stack related to the given exception.

@keegan-caruso
Copy link
Contributor

hi @JFFby I am not able to reproduce this. Can you confirm that this doesn't repro on a clean new app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product is not functioning as expected P1 More important, prioritize highly Regression
Projects
None yet
Development

No branches or pull requests

3 participants