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

Custom issuer #77

Merged
merged 3 commits into from
Mar 26, 2019
Merged

Custom issuer #77

merged 3 commits into from
Mar 26, 2019

Conversation

ryan-rosenfeld
Copy link
Contributor

@ryan-rosenfeld ryan-rosenfeld commented Mar 25, 2019

Changes

  • Added the ability to specify a custom issuer for JWT validation that differs from the provided domain

References

  • I'm an employee at Atlassian on the Statuspage team. We are using this gem to authenticate with our internal authentication service, however the JWT generated by our internal auth service comes from auth0 servers and not from our internally hosted site. Since we make requests to our internal service, the domain is different from the generated JWT. So, to use this gem this change is necessary or else it will always fail JWT validation.

Testing

Unit tests have been added to reflect the added change, and we tested locally with our setup.

Checklist

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

I'll summon @joshcanhelp for a second pair of eyes as this is not my language.

lib/omniauth/auth0/jwt_validator.rb Show resolved Hide resolved
@@ -10,6 +10,7 @@
let(:client_id) { 'CLIENT_ID' }
let(:client_secret) { 'CLIENT_SECRET' }
let(:domain) { 'samples.auth0.com' }
let(:issuer) { 'samples.auth0.com' }
Copy link
Contributor

Choose a reason for hiding this comment

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

if the issuer is the same as the domain, how can the test check that it changed?

describe 'JWT verifier custom issuer' do
context 'same as domain' do
let(:jwt_validator) do
make_jwt_validator(opt_issuer: issuer)
Copy link
Contributor

Choose a reason for hiding this comment

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

I rather you pass the issuer value here instead of declaring a global variable that is only going to be used for this single test context.

)
)
def make_jwt_validator(opt_domain: domain, opt_issuer: nil)
opts = if opt_issuer.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

You already have as part of the initialize method of the verifier a check for the presence of the issuer value.

if options.respond_to?(:issuer)

Can't you instantiate it directly using named arguments? Like you did here https://github.com/auth0/omniauth-auth0/pull/77/files#diff-708c8cee2bf0dc225b55a0c36afaa97dR260. Why do you need to use Options and OptionsWithIssuer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, didn't realize Options was a Struct and not an OpenStruct before and was confused why I couldn't add values, which is why I made a different struct. Switching the implementation to use an OpenStruct where I add the issuer if it's there. Can't pass in the issuer if it's nil because the OpenStruct/Struct will return true for the respond_to? method, even though the value it returns is actually nil.

@joshcanhelp
Copy link
Contributor

@ryan-rosenfeld - Thanks for the PR here! I agree with @lbalmaceda's assessment here. If you can walk through the changes here (and run rubocop on any changed files), I'd be happy to get this merged and a new release cut ASAP.

@joshcanhelp joshcanhelp added this to the v2-Next milestone Mar 26, 2019
@ryan-rosenfeld
Copy link
Contributor Author

Thanks so much for the attention @joshcanhelp and @lbalmaceda, really appreciate it! I will address your comments asap and let you know once my changes are up 👍

@ryan-rosenfeld
Copy link
Contributor Author

Okay, the PR should be updated based on your feedback. Ran both files through rubocop and they checked out. Let me know if there are any other changes you'd like me to make!

Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

@ryan-rosenfeld - Looks great!

And just to make sure ... this was tested in your internal auth service?

@ryan-rosenfeld
Copy link
Contributor Author

Awesome, thanks @joshcanhelp! Yes I did, I tested by monkeypatching the current version of the gem with the exact changes I made here, and it worked as desired for our usage scenario using the custom issuer.

@joshcanhelp joshcanhelp merged commit 278aa9f into auth0:master Mar 26, 2019
@joshcanhelp
Copy link
Contributor

@ryan-rosenfeld Thank YOU!

I'll get this released first thing next week.

@scootklein
Copy link

hey @joshcanhelp, any luck in cutting a new version to rubygems? any eta you can provide us? we're looking to get this monkeypatch out of production and would love if we could get the native gem in

thanks!

@joshcanhelp
Copy link
Contributor

So sorry for the delay, this totally slipped through the cracks. Pushing this out right now.

@scootklein
Copy link

thanks for the update to master. any idea when rubygems cache will pop? seems like it still only has the most recent version

@joshcanhelp
Copy link
Contributor

I see it live on RubyGems:

https://rubygems.org/gems/omniauth-auth0

@scootklein
Copy link

scootklein commented Apr 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants