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

Failure to sign with explicit header in token. #48

Closed
RubenGarcia opened this issue Nov 3, 2023 · 3 comments
Closed

Failure to sign with explicit header in token. #48

RubenGarcia opened this issue Nov 3, 2023 · 3 comments

Comments

@RubenGarcia
Copy link

dart_jsonwebtoken: ^2.12.0

This code

    Map<String, String> h = {
      "alg": "HS256",
      "typ": "JWT",
    };
    Map<String, dynamic> p = {
      "sub": "1234567890",
      "name": "John Doe",
      "iat": 1516239022
    };
    SecretKey s = SecretKey("");
    JWTAlgorithm a = JWTAlgorithm.HS256;

    final j = JWT (p, header: h);
    final t = j.sign(s, algorithm: a);

Fails with error

type '_Map<String, dynamic>' is not a subtype of type 'Map<String, String>' of 'other'

in line

      header!.addAll({'alg': algorithm.name, 'typ': 'JWT'});
@RubenGarcia
Copy link
Author

Removing the header argument results in a correct token.

@jonasroussel
Copy link
Owner

Hi @RubenGarcia,
It seems to be a map typing problem, I think the function addAll is not the right method to add the default values of alg and typ.
I'll see if I can fix the problem.

@jonasroussel
Copy link
Owner

Fixed in the last version!
https://pub.dev/packages/dart_jsonwebtoken/versions/2.12.1

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

No branches or pull requests

2 participants