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

jsonwebtoken fails to verify valid token #80

Closed
samuela opened this issue Mar 18, 2019 · 5 comments
Closed

jsonwebtoken fails to verify valid token #80

samuela opened this issue Mar 18, 2019 · 5 comments

Comments

@samuela
Copy link

samuela commented Mar 18, 2019

I have a known valid token, verified with https://jwt.io/. Yet, no matter what I do jsonwebtoken declares InvalidSignature. Here's an example:

fn main() {
  let token = "eyJ0e...available privately on request......hbQQ";

  let pem = "-----BEGIN CERTIFICATE-----
MIIC/TCCAeWgAwIBAgIJIayPWv6q6acCMA0GCSqGSIb3DQEBCwUAMBwxGjAYBgNV
BAMTEW51dmVtZnMuYXV0aDAuY29tMB4XDTE5MDEyMTAxMTEyNloXDTMyMDkyOTAx
MTEyNlowHDEaMBgGA1UEAxMRbnV2ZW1mcy5hdXRoMC5jb20wggEiMA0GCSqGSIb3
DQEBAQUAA4IBDwAwggEKAoIBAQCvsckLZecpNoAx1nsJRo2h1WyEb2Kc7Guard/j
pxxD7QMjCdOPGtWdoAq2yqKceKGhhojgqFMCBhx/eqeScaAl2Kvf59cl7JWxDVJ+
n9givgQVPy5ZczvimZZMQCwr8F7/IJ2kkTdVR0ytNclVGZqmxzrSiTIev0Hlf09W
JaQipRNI5Yv7yCYv1/P6xXozmdtmO0yjjNEXCY/+T36n8S72XUkX6VfKx09ZkLbT
y9gxyg9X7idnr2Jg93m9RmyO8xay1vQBZxkxM4kKYOlLOGpoulolALfgkf9cR09G
zojQxuBKfROCYVLfHMsN3IiNSs1J40/iPea1r+ZsDiTPrbZdAgMBAAGjQjBAMA8G
A1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFEBuuLqv76vx3TZ7DIe/Y3pk6MjTMA4G
A1UdDwEB/wQEAwIChDANBgkqhkiG9w0BAQsFAAOCAQEAq3fyyi8Sl92P54gIxOhV
Q5OXet4bhETaW792XgMWhfcG/ppbZwT1krWflDps9BzSfNI7WpPAdreYk+hKSuCu
oNVU0imgha+1SKwxcRbW6Gx9XTn7aTIqP7xxk5uRLO79O5Dhy0d/1YVHpJJK2lKZ
Ridu3W1hbBvXPWgtl4jgYPYmoUcFH/jv0PP4H1ka7rnV6JLtqEBB1naSfYhA3U9s
3VvcS03EPDZIoiNzsiPu4qepVbf/mprxFEztR9HCqHGE+1oBxmt+wjfVRgIDGHcY
rWr2f6rC/AfuqOsPayb4SLQIFujxqJ0nwy3CUrlAlfQvYOnrkMQoccj2nklY86kl
Gw==
-----END CERTIFICATE-----";

  let der = openssl::x509::X509::from_pem(pem.as_bytes())
    .unwrap()
    .to_der()
    .unwrap();

  let decoded = jsonwebtoken::decode::<AccessToken>(
    token,
    &der,
    &jsonwebtoken::Validation {
      algorithms: vec![jsonwebtoken::Algorithm::RS256],
      ..Default::default()
    },
  );

  println!("{:?}", decoded)
}

No matter what jsonwebtoken returns Err(Error(InvalidSignature)). The payload looks like:

{
  "https://hasura.io/jwt/claims": {
    "x-hasura-default-role": "user",
    "x-hasura-allowed-roles": [
      "user"
    ],
    "x-hasura-user-id": "......."
  },
  "iss": "https://nuvemfs.auth0.com/",
  "sub": "google-oauth2|.......",
  "aud": [
    "https://nuvenmfs/api",
    "https://nuvemfs.auth0.com/userinfo"
  ],
  "iat": 1552895641,
  "exp": 1552982041,
  "azp": "......",
  "scope": "openid profile email offline_access"
}
@samuela
Copy link
Author

samuela commented Mar 18, 2019

Potentially related to #77 ?

@Keats
Copy link
Owner

Keats commented Mar 18, 2019

It does look related, closing this to keep things in a single thread.

@ndarilek
Copy link

@samuela
samuela Looks like you're doing exactly what I am--writing a Hasura auth webhook to verify an Auth0 JWT. Did you ever make any progress on this? Right now I'm just pasting in static tokens/certificates and am hitting this exact same issue. I don't want to give up and switch to Node if I can avoid it. :) Thanks.

@samuela
Copy link
Author

samuela commented May 15, 2019

@ndarilek I gave up and switched to node :( I wasn't able to find a satisfactory solution with any of the rust jwt libraries unfortunately. Hoping that this aspect of the ecosystem matures in the future...

@ndarilek
Copy link

Gotcha. Thanks for saving me some time.

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

3 participants