-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Review and verify guide on Auth0 JWT Integration #2655
Comments
@fogelfish thank you for reporting this. This is good to know. We will try it out and fix the documentation 👍 |
On a similar note, I've been using the I found this could be fixed by simply attaching the Hasura namespace claims to Please see https://community.auth0.com/t/how-to-obtain-id-token-with-auth0-spa-js/27574/10 (if it hasn't already been brought to your attention...) (Happy to submit a docs PR if there is no particular issue with this...) |
@thetre97 you're right. The SDK doesn't expose the ID token and they recommend to use access tokens. I'm not sure of the reason(s) though. Generally speaking, ID tokens are issued to end users, containing user information, and access tokens are meant for applications to access APIs. See ID token, Access tokens. Hasura requires a JWT with the Hasura specific claims, as long as it is there in a JWT it should work. |
@thetre97 - Hi, from version 1.2.0 and above, the raw idToken value is available in the |
@praveenweb Great, thanks - will check that out 👍 |
I'm currently evaluating hasura + auth0 flow. One thing I noticed is that auth0 discourages using idToken for API access and instead encourages the use of accessToken. I've also noticed that the ID token can get very large, depending how much user info and metadata is being stuffed into it, so using it for each and every API call as a header does not seem great practice. Here an extract from docs (https://auth0.com/docs/api-auth/why-use-access-tokens-to-secure-apis#how-not-to-use-tokens)
|
You can (and should) use an access token, and it's not too difficult:
const authConfig = {
domain: 'example-hasura-app.auth0.com',
client_id: 'someg0bbledyg00k',
redirect_uri: window.location.origin, // or whatever you're doing for this
scope: 'openid email profile',
audience: 'https://example-hasura-app.herokuapp.com'
}
function (user, context, callback) {
const namespace = "https://hasura.io/jwt/claims";
context.accessToken[namespace] = {
'x-hasura-default-role': 'user',
'x-hasura-allowed-roles': ['user'],
'x-hasura-user-id': user.user_id
};
callback(null, user, context);
}
|
Thats some great info @tehpsalmist, thanks a ton for letting me know, it works perfectly, should go directly into official docs! |
@tehpsalmist thank you so much for helping out! I make sure this will be added to the docs within the next 2-3 weeks 🙂 |
@tehpsalmist I have to echo everyone's appreciation posted the fix. I was banging my head against this for a couple of hours and that change to |
Hi everyone, @praveenweb and I have tried out the above instructions and we both were not able to get a valid JWT token through the @westhechiang @bkniffler @tehpsalmist @thetre97 We think it might have something to do with Auth0 releasing a new version of their SDK ( |
@marionschleifer I‘m not using the js library, I‘ve implemented everything with calls to auth0 API from electronjs (so nodeJS) and it works pretty great. Thanks for hinting the new SDK though, didn‘t see they have a new one in the works. |
Yeah, I'm not sure, but I think I was working on 1.2.3 or something when I submitted my PRs and had lengthy conversations with auth0 about this stuff. I'm spinning up a new app right now, so I'll report back if none of this works. |
Upon further reflection, the client-side auth0 library should have no effect on whether the token is JWT or not. The important step is in setting up that API on the auth0 account. Can you post your repro steps? |
I'm definitely succeeding again with the above steps, using auth0-spa-js 1.2.4. I had previously been using 1.0.2, so I can now confirm the same steps worked before and after the changes you referenced. Let me know if there's anything I can do to help you troubleshoot your specific difficulties. |
@bkniffler @tehpsalmist thank you for your comments and for your help 🙂 @praveenweb will re-write the guide taking your comments and recent findings into consideration. @praveenweb also take a look at this: https://discordapp.com/channels/407792526867693568/428469959530643466/630286971700248586 🙂 |
Co-authored-by: Praveen Durairaju <praveend.web@gmail.com>
Following the instructions here, I encountered problems when using the suggested URI under the heading Test auth0 login and generate sample JWTs for testing. Two things: first, if you want to use the /login endpoint you have to substitute
with
Second, for the /login endpoint to work, as given in these instructions, you have to disable OIDC Compliance under the Auth0 application you are targeting, found under Applications > <your-hasura-application> > Settings > Advanced Settings > OAuth. If you don't do this Auth0 will give an error after you submit the login form:
I am a beginner at all of this. It may be that these instructions worked before Auth0 disabled "as many legacy features as possible". I quote from auth0 docs. I hope this is useful info.
The text was updated successfully, but these errors were encountered: