Skip to content

Commit

Permalink
Prefer id_token over access_token in JWT decode (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
zquestz committed Sep 5, 2022
1 parent 35b6c74 commit 24c6d59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 24c6d59

Please sign in to comment.