achedeuzot / ueberauth_auth0

Auth0 OAuth2 strategy for Überauth.
https://hexdocs.pm/ueberauth_auth0
MIT License
71 stars 46 forks source link

Replace `/userinfo` call with the existing JWT info #192

Open hexedpackets opened 2 years ago

hexedpackets commented 2 years ago

The response from auth0 when authorizing returns both a token and an id_token. The id_token seems to have the same information as the /userinfo endpoint, making the extra call unnecessary.

Would you be open to a PR that decodes the id_token JWT for creating the user struct? The reason I want to do this is if an Auth0 API is using HS256 as its signing algorithm, there's no way to get an access token for both the API and the /userinfo endpoint.

achedeuzot commented 2 years ago

Hi @hexedpackets, thanks for your other pull-request :)

I'd be happy to remove the call to /userinfo under two conditions:

Thanks very much for your contribution !

hexedpackets commented 2 years ago

So as far as documentation, the most explicit page I've found is the OpenID Connect Scopes description which states:

Once the user authorizes the requested scopes, the claims are returned in an ID Token and are also available through the /userinfo endpoint.

The ID Token Structure page also describes the token in more detail, although it doesn't mention /userinfo, just the OIDC claims in general.

I can't say if it was always the case or when it might have changed, but the current OAuth code exchange will always return the ID token. The Authorization Code Flow doc states this:

  1. Your Auth0 Authorization Server responds with an ID Token and Access Token (and optionally, a Refresh Token).

It might not be the case for other flows, but unless I'm mistaken the code exchange is the only OAuth flow this library uses.

Does that evidence sound reasonable to you? I actually already have the JWT decoding on a branch in my fork, so it would be pretty quick to put together a PR for it.

achedeuzot commented 2 years ago

Hey :)

This evidence sounds reasonable indeed. Let's try this. Let's create the PR and I'll do some tests on a live auth0 system to check if I always get a JWT ID token even when changing the auth0 options and if it works, we'll use it instead of the /userinfo endpoint. Do you think it would be interesting to add an option to allow users to choose which method to use ? I'n not sure there is but you may have an idea. Also, please include some tests if possible to ensure we have proper testing of this new way of doing things.

Thank you very much !

taj commented 1 year ago

Hello!

We are running into Rate Limit errors because of this, Auth0 support suggested we use the id_token as well. I'll take a stab at implementing this in the next few days!

taj commented 1 year ago

@achedeuzot Draft PR here: https://github.com/achedeuzot/ueberauth_auth0/pull/235

What do you think? :)