Skip to content

Support at+jwt auth token #75

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

Open
pierre-H opened this issue Apr 25, 2025 · 13 comments
Open

Support at+jwt auth token #75

pierre-H opened this issue Apr 25, 2025 · 13 comments

Comments

@pierre-H
Copy link

It would be great to support JWT with the at+jwt type (OIDC standard).

For example : Logto access tokens are at+jwt tokens.

@nipunn1313
Copy link
Collaborator

Can you give an example or provide more information about this OIDC standard token type?

Supporting logto from Convex seems like a great idea.

Have you tried it? Convex supports any provider supporting OIDC https://docs.convex.dev/auth/advanced/custom-auth

What happens when you try it with Logto?

@pierre-H
Copy link
Author

The access token is a JWT token. Its main advantage is that it contains the "scopes" (in addition to the user ID and other information that can be added manually). The "scopes" a string with all the permissions linked to a user based on their role (e.g., "read:logs, write:logs, read:users, write:users").
The ID token is the standard JWT that only contains the user's information. The access token has a shorter expiration time, which requires, for security reasons, more frequent refreshing (usually every hour).

For more information about access tokens: https://blog.logto.io/understanding-tokens-in-oidc and https://auth-wiki.logto.io/access-token.

With Logto, I can create permissions (scopes) and assign them to roles. Then each user can be assigned one or more roles and thus have the corresponding permissions.

Logto allows separating scopes by API resources. Regarding integration with Convex, I consider my Convex database (an excellent product, by the way, thank you very much!!) as an API resource. My goal would be to send the access token directly. This way, in my Convex functions, I can directly verify whether a user has access to a function via the access token without any fetch.
Moreover, with this solution, there is no need to store permissions in Convex via a webhook.
The access token serves both authentication and authorization purposes on the Convex side.

Regarding integration with Logto, I have indeed succeeded with the ID token (the standard JWT with the user's basic information). It integrates very well with Convex (see https://discord.com/channels/1019350475847499849/1184230782370320396). The only thing missing, which would be fantastic, is support for the at+jwt type of JWT.

The reason I chose Logto is that it can be self-hosted (very important, like Convex), is straightforward to use, and has a management API. I didn’t want to use Clerk or Auth0 because they are not self-hostable. As for Convex Auth, I had to set it aside because I use SvelteKit, not React.
I tried using Better Auth, but the current plugins are all in alpha for now, and Logto’s solution is much more stable and simple today.


I strongly recommend adding Logto integration to the documentation.
But above all, support for access tokens with at least acceptance of this type of token.

@pierre-H
Copy link
Author

pierre-H commented May 1, 2025

Hi @nipunn1313,
What's your opinion about that ?

@nipunn1313
Copy link
Collaborator

Broadly seems reasonable to add support for a new JWT token format - but I am struggling to find any documentation about what this at+jwt token is? Neither of the links you sent referenced it.

It would likely have to go in here https://github.com/get-convex/convex-backend/blob/main/crates/authentication/src/lib.rs#L430 - would you like to try to implement it and test it out?

If you can implement it and link to documentation explaining the at+jwt type, that seems reasonable.

@thomasballinger
Copy link
Contributor

@pierre-H we're starting to support things like this; could you take a look at https://docs.convex.dev/auth/advanced/custom-jwt and see if that fits?

@pierre-H
Copy link
Author

pierre-H commented May 3, 2025

@nipunn1313 : here is the RFC : https://datatracker.ietf.org/doc/html/rfc9068#section-4 . The RFC 9068 is about Access tokens.
I am not sure if I could implement it as I don't know anything about Rust, but I will try with some LLM helps ...

@thomasballinger : I tried, and I still have the error: Unsupported: unexpected or unsupported JWT type at+jwt.

@thomasballinger
Copy link
Contributor

@pierre-H you'll still need to use the type "customJwt", but you may be able to make this work by setting the other fields; would love to hear how this goes!

@juliusmarminge
Copy link

Hey @thomasballinger. Trying to set up the custom jwt provider with better-auth, but the example config from the docs fails to deploy:

Image

Image

Ideas?

@pierre-H
Copy link
Author

Hi @juliusmarminge,
I don't think this is related to the at+jwt token. You should create a new issue for that.

@thomasballinger
Copy link
Contributor

@pierre-H what does an at+jwt JWT look like? I bet with custom jwt support this will be possible.

I chatted with @juliusmarminge separately, more docs coming on custom jwt auth soon.

@pierre-H
Copy link
Author

pierre-H commented May 14, 2025

@thomasballinger it' something like :

{
    "email": "myemail@convex.com",
    "username": "pierre-H",
    "jti": "xxx",
    "sub": "xxx",
    "iat": 1747205352,
    "exp": 1747208952,
    "scope": "order:read order:write stock:read",
    "client_id": "xxx",
    "iss": "https://instance.convex.com/oidc",
    "aud": "https://instance.convex.com",
  }

The most important part are:

  • scope which contains all current authorization of the user
  • aud which is the name of the API

In logto, we configure this in the Api Resources section.

@thomasballinger
Copy link
Contributor

It looks like this would work with customJwt, although not sure that exposes scope yet. I'm documenting this new flow this week, if you get a chance to try this let me know and I can explicitly mention it.

@pierre-H
Copy link
Author

Thank you, @thomasballinger! As soon as the documentation is updated, I will try it.

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

4 participants