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

Replace API calls to /userinfo with payload from id_token #235

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

taj
Copy link

@taj taj commented Jan 26, 2023

We are going above Auth0's rate limits on a daily basis.
After some investigation we realised that the ueberauth_auth0 was making API calls to the /userinfo endpoint every time someone logs in (on callback).

We actually don't need to do this as the user info is returned in the id_token.
The id_token follows the the JWT standard.

@taj taj marked this pull request as draft January 26, 2023 15:25

{:error, %Response{body: body}} ->
set_errors!(conn, [error("OAuth2", body)])
[_header, payload, _signature] = String.split(id_token, ".")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to validate the JWT instead of manually parsing it ?
It doesn't look like a good idea to skip signature and header checks.

Be sure to validate ID tokens before using the information it contains.

You can add one of these three libs: https://jwt.io/libraries?language=Elixir
I would suggest using joken as it's the most complete and lightweight given the task.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heya @achedeuzot 100%
This is just WIP, I am currently working on adding the JWT validation! This means there will be a breaking change in Auth0 as we have to start requiring all devs to use the .pem signing keyfrom Auth0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achedeuzot can you have a look now? :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taj Thanks so much for your contributions. I'm a bit overwhelmed with tasks lately but will have a look very soon (and if everything goes well, will be able to release a new package).

Copy link
Author

@taj taj Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achedeuzot no worries, take your time! We have forked this repo and have been using this branch in our production applications already and everything seems to be working correctly.
Let me know if I need to provide any further info or support!

assert conn.resp_body =~ ~s|scope=openid+profile+email|
assert conn.resp_body =~ ~s|state=#{conn.private[:ueberauth_state_param]}|
end
describe "handle_request!" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split the test refactoring into 2 separate commits or, even better, into two separate pull requests ? This will make the reviewing easier by first moving the tests into describe blocks with no changes and then add tests for the current PR. Right now I'm having some trouble to find what has really changed from what is a simple refactor ? Thanks :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually refactored the existing tests which are on the master branch as well as fixed the CI tests. If you rebase it should be quite fast to update your branch :)

@taj taj force-pushed the sc-21571/fix-ueberauth-auth0-rate-limit branch 2 times, most recently from ceba09c to bb88f23 Compare February 2, 2023 14:04
@taj taj marked this pull request as ready for review February 2, 2023 14:05
@@ -3,7 +3,7 @@ use Mix.Config
config :ueberauth, Ueberauth,
json_library: Jason,
providers: [
auth0: {Ueberauth.Strategy.Auth0, []}
auth0: {Ueberauth.Strategy.Auth0, [signer_module: SpecSignerModule]}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add some docs for this

@taj taj force-pushed the sc-21571/fix-ueberauth-auth0-rate-limit branch from bb88f23 to c4ef00d Compare February 2, 2023 16:20
@achedeuzot
Copy link
Owner

BTW, have you seen the #175 PR ? It could give you some ideas about your feature ;)

@achedeuzot
Copy link
Owner

@taj In ran the CI but it's red because of a few things :) Have you checked the PR of the previous comment ? It could help ;)

@taj
Copy link
Author

taj commented Feb 20, 2023

@taj In ran the CI but it's red because of a few things :) Have you checked the PR of the previous comment ? It could help ;)

Hey @achedeuzot, sorry was on holiday for the past week, I will try to fix everything this week! :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants