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

Invalid issuer. Expected accounts.google.com, received https://accounts.google.com #292

Closed
blaedj opened this issue Jul 19, 2017 · 9 comments

Comments

@blaedj
Copy link
Contributor

blaedj commented Jul 19, 2017

I'm running into the error JWT::InvalidIssuerError: Invalid issuer. Expected accounts.google.com, received https://accounts.google.com , is seems that google is sending 'https://accounts.google.com' instead of 'accounts.google.com' as the iss?

Should there be a way to specify the iss to verify? (referencing https://github.com/zquestz/omniauth-google-oauth2/blob/master/lib/omniauth/strategies/google_oauth2.rb#L64 here)

my omniauth.rb file:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider  :google_oauth2, 
            Rails.application.secrets.google_client_id, 
            Rails.application.secrets.google_client_secret,
            {
              :name => "google",
              :scope => "email, profile, https://www.googleapis.com/auth/admin.directory.user.readonly",
              :prompt => "consent",
              :access_type => 'offline'
            }
end
blaedj added a commit to kolide/omniauth-google-oauth2 that referenced this issue Jul 19, 2017
this would be a workaround for issue zquestz#292. Google's own libraries for
oauth don't verify iss, and it seems that they've recently changed the
iss to `http://accounts.google.com` from `accounts.google.com`
@zquestz
Copy link
Owner

zquestz commented Jul 20, 2017

Seems it is something to do with your custom scope. The default example still returns accounts.google.com. I think the best solution is to make sure iss is configurable to support this odd behavior.

zquestz pushed a commit that referenced this issue Jul 20, 2017
this would be a workaround for issue #292. Google's own libraries for
oauth don't verify iss, and it seems that they've recently changed the
iss to `http://accounts.google.com` from `accounts.google.com`
@zquestz
Copy link
Owner

zquestz commented Jul 20, 2017

K did a bunch of testing and google has made it impossible to verify iss correctly as the value changes between accounts.google.com and https://accounts.google.com at random. Even if we could set it, there is no reliable way to know what they will return.

Serious lack of thought on google's behalf.

@zquestz zquestz closed this as completed Jul 20, 2017
soundasleep added a commit to soundasleep/railswiki that referenced this issue Jul 20, 2017
Fixes "Invalid issuer. Expected accounts.google.com, received https://accounts.google.com" error on deploy.
See zquestz/omniauth-google-oauth2#292

Also update docs on using webpacker
@soundasleep
Copy link

Thank you for the quick fix! <3

Rather than disabling ISS verification completely, could we do something like this (capturing exceptions if necessary)?

success = test_iss("accounts.google.com") || test_iss("https://accounts.google.com")

That way we can at least check it's one that we expect. (I don't know ISS/JWT at all though so not sure if this is feasible)

@zquestz
Copy link
Owner

zquestz commented Jul 21, 2017

Yeah that was originally going to be my approach but double validating the JWT isn't a great idea. Honestly Google doesn't even validate the ISS in their own clients, so I think the current solution is just fine. I am guessing eventually it will only return https://accounts.google.com, and when that happens we can adjust the code to only use that.

@ilgianlu
Copy link

ilgianlu commented Jul 21, 2017

Why can't just parse iss as URI and take server part... sort of domain verification.
Just my thought.

From RFC:
The "iss" value is a case-sensitive string containing a StringOrURI value.
Anyway.. I agree with "Serious lack of thought on google's behalf."

@zquestz
Copy link
Owner

zquestz commented Jul 21, 2017

Its not something you can parse, it is passed into JWT.decode as an option. The only other option is to try and decode the JWT token twice for both cases. I wish it was as simple as parsing it. =(

@pior
Copy link

pior commented Jul 25, 2017

@zquestz Can you provide an example of Google clients not validating the iss field?

@pior
Copy link

pior commented Jul 25, 2017

Google has a million docs about their APIs, but at least one specify how to validate this field:

The value of iss in the ID token is equal to accounts.google.com or https://accounts.google.com.

https://developers.google.com/identity/sign-in/web/backend-auth

@dark-panda
Copy link

Starting with JWT 2.0, you won't need to decode the JWT token twice, as JWT::Verify#verify_iss itself will allow for an array of values to check against. See https://github.com/jwt/ruby-jwt/blob/master/lib/jwt/verify.rb#L44 and the specs at https://github.com/jwt/ruby-jwt/blob/master/spec/jwt/verify_spec.rb#L128 for details. The fix, then, can be changing the :iss option to JWT.decode to

iss: ['accounts.google.com', 'https://'accounts.google.com']

This was changed in jwt/ruby-jwt#210 to allow for this specific case where Google returns multiple iss values.

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

6 participants