Okta JWT as header Authorization Bearer Token #2868
Unanswered
justinlevi
asked this question in
Help
Replies: 1 comment 6 replies
-
the Okta token is not the same as the one generated by NextAuth.js |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Question 💬
Thanks in advance for any help. Really appreciative of all the work that's gone into this project.
I'm likely missing something fundamental, and just going in circles at this point, but hoping someone can point me in the right direction. I'm pretty new to NextJS and Oath2.0 in general so apologies if there is something basic I'm missing here.
Overview:
I have a NextJS App with an external GraphQL API. I need to authenticate via Okta and pass along the accessToken to the external API via an
Authorization
header. On the external Apollo GraphQL API I then need to verify the token against Okta for each GraphQL query/mutation to ensure the current user has permission to access a given resource.What I have tried:
I setup an api proxy in my NextJs app based on @iaincollins response on issue #320, with the thought that I could set the Authorization header there using .
#320 (comment)
This does set the header, which I can then access via the API. The problem is when I try to verify this token from the API with Okta, I get the following error:
Side note: this is the proxy approach I took using
createProxyMiddleware
.vercel/next.js#14057
Using jwt.io, If I look at the token, I can see that algorithm is using
"alg": "HS512"
which is the default algo that NextAuth uses to encode the JWT.I also tried using the code from #320 to get the encrypted token from the session cookies
But I get the error
Error: Malformed UTF-8 data
which doesn't make any sense to me.My
secret
environment variable is set to a random set of characters.Question/Issues:
RS256
algo, which is what Okta expects? (example here? getToken returns null when raw=false, but works with raw=true #523 (comment))node-jose-tools
based off the thread I'm seeing here? How to resolve [next-auth][warn][jwt_auto_generated_signing_key] #484getToken returns null when raw=false, but works with raw=true #523 (comment)
At this point my head is generally spinning and I'm not sure where to turn. This feels like a pretty common requirement so I'm wondering if I'm missing something obvious.
Some reference issues I've found that seem to have similar issues:
#320
#1290
#523 (comment)
Using getToken
https://github.com/nextauthjs/next-auth-example/blob/main/pages/api/examples/jwt.js
How to reproduce ☕️
I'm working on putting together a simple demo example and will try to update this issue.
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Beta Was this translation helpful? Give feedback.
All reactions