JWT is not valid when cheking on jwt.io #1039
-
Hi, I'm working on writing an article about how to connect NextAuth + Hasura in an easy way. I think I configured settings properly and the application works. However, if I try to paste my token to jwt.io it can't verify the token signature. .env.local
And I have an API endpoint
I can log in using an authentication provider, the application works, but if I choose Do you know what I might be doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi there! This fails because the Currently there isn't a way to export the key that is generated by NextAuth.js - though it's something we could certainly expose via the Node.js API and/or CLI in future. If you are curious what it looks like, you can find the code for it here. If you want to generate your own key from that secret value you could write a function like this: function getSigningKey (secret) {
const buffer = hkdf(secret, 64, { info: 'NextAuth.js Generated Signing Key', hash: 'SHA-256' })
const key = jose.JWK.asKey(buffer, { alg: DEFAULT_SIGNATURE_ALGORITHM, use: 'sig', kid: 'nextauth-auto-generated-signing-key' })
return key
} Passing the secret to this function and using this response as your your key should work as you'd expect! |
Beta Was this translation helpful? Give feedback.
-
@iaincollins the |
Beta Was this translation helpful? Give feedback.
-
Also, could anyone please tell me if I am following the right path here to solve this problem: |
Beta Was this translation helpful? Give feedback.
Hi there!
This fails because the
JWT_SECRET
is used to generate a key suitable for signing but isn't really the key itself - it's more a value used to seed a derived key.Currently there isn't a way to export the key that is generated by NextAuth.js - though it's something we could certainly expose via the Node.js API and/or CLI in future. If you are curious what it looks like, you can find the code for it here.
If you want to generate your own key from that secret value you could write a function like this: