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

Prefer id_token over access_token in JWT decode #431

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/omniauth/google_oauth2/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module OmniAuth
module GoogleOauth2
VERSION = '1.1.0'
VERSION = '1.1.1'
end
end
9 changes: 5 additions & 4 deletions lib/omniauth/strategies/google_oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def authorize_params

extra do
hash = {}
hash[:id_token] = access_token.token
if !options[:skip_jwt] && !nil_or_empty(access_token.token)
decoded = ::JWT.decode(access_token.token, nil, false).first
token = nil_or_empty?(access_token['id_token']) ? access_token.token : access_token['id_token']
hash[:id_token] = token
if !options[:skip_jwt] && !nil_or_empty?(token)
decoded = ::JWT.decode(token, nil, false).first

# We have to manually verify the claims because the third parameter to
# JWT.decode is false since no verification key is provided.
Expand Down Expand Up @@ -108,7 +109,7 @@ def custom_build_access_token

private

def nil_or_empty(obj)
def nil_or_empty?(obj)
obj.is_a?(String) ? obj.empty? : obj.nil?
end

Expand Down