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

Username in ID token #257

Open
cornerman opened this issue Apr 5, 2024 · 7 comments
Open

Username in ID token #257

cornerman opened this issue Apr 5, 2024 · 7 comments

Comments

@cornerman
Copy link
Contributor

When using authn, I realized that the id token (e.g. in authn-js accessed via authn.sessionToken()) does not contain the username. Is it possible to get this info into the id token issued by authn-server, so the frontend has direct knowledge about it?

@AlexCuse
Copy link
Contributor

AlexCuse commented Apr 5, 2024

There's email and preferred_username claims defined here https://www.iana.org/assignments/jwt/jwt.xhtml

Either could make sense depending how authn is configured.

@cornerman
Copy link
Contributor Author

That sounds right - depending whether usernames are configured as emails. Do I understand correctly, that this is not yet possible with configuration? Can I help with adding support for this?

@AlexCuse
Copy link
Contributor

I don't see any reason it would hurt, I think a PR would make sense. I'm not sure if we would want to make inclusion configurable or not - the relative anonymity is something I always liked about JWTs but not sure if its a must-have. @cainlevy any thoughts here?

@cainlevy
Copy link
Member

My only concern is token length, and I don't know off the top of my head if that could be a concern for anyone.

Another way to get this information in a client might be a session endpoint that returns a few details about the current token's account.

@cornerman
Copy link
Contributor Author

Thank you for your answers. I would definitely prefer username/email in the ID token, because of latency when calling a dedicated endpoint. That would be for the frontend and the backend.

Do we know what kind of length concerns there are for the token?

@cornerman
Copy link
Contributor Author

About anonymity: a lot of setups use a separate id and access token. So, the access token without identifiable information can be sent to the server.

For the token length: making it configurable would probably make all sides happy then :)

@AlexCuse
Copy link
Contributor

Yeah the dedicated endpoint makes sense to me - #253 is adding an endpoint to retrieve oauth account details and it sort of fits in with that, it could be changed to eg /account/info to include the username as well. You could call this once after login and store it in session / cookie if latency is a concern.

That said I can see how it would be convenient to include in token. Probably relatively safe as long as its configurable / opt-in. Would need to update at least the go client to include the new claim as well I think.

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