Skip to content

Commit

Permalink
Merge pull request #15 from appsent-co/master
Browse files Browse the repository at this point in the history
allow dynamic client_ids
  • Loading branch information
nhosoya committed May 14, 2020
2 parents 3610fb4 + e06de50 commit aff3e96
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/omniauth/strategies/apple.rb
Expand Up @@ -13,7 +13,8 @@ class Apple < OmniAuth::Strategies::OAuth2
token_url: '/auth/token'
option :authorize_params,
response_mode: 'form_post'

option :authorized_client_ids, []

uid { id_info['sub'] }

info do
Expand All @@ -32,7 +33,7 @@ class Apple < OmniAuth::Strategies::OAuth2
end

def client
::OAuth2::Client.new(options.client_id, client_secret, deep_symbolize(options.client_options))
::OAuth2::Client.new(client_id, client_secret, deep_symbolize(options.client_options))
end

def callback_url
Expand All @@ -42,9 +43,19 @@ def callback_url
private

def id_info
id_token = request.params['id_token'] || access_token.params['id_token']
log(:info, "id_token: #{id_token}")
@id_info ||= ::JWT.decode(id_token, nil, false)[0] # payload after decoding
if request.params&.key?('id_token') || access_token&.params&.key?('id_token')
id_token = request.params['id_token'] || access_token.params['id_token']
log(:info, "id_token: #{id_token}")
@id_info ||= ::JWT.decode(id_token, nil, false)[0] # payload after decoding
end
end

def client_id
unless id_info.nil?
return id_info['aud'] if options.authorized_client_ids.include? id_info['aud']
end

options.client_id
end

def user_info
Expand All @@ -70,7 +81,7 @@ def client_secret
payload = {
iss: options.team_id,
aud: 'https://appleid.apple.com',
sub: options.client_id,
sub: client_id,
iat: Time.now.to_i,
exp: Time.now.to_i + 60
}
Expand Down

0 comments on commit aff3e96

Please sign in to comment.