diff --git a/lib/apple_auth/token.rb b/lib/apple_auth/token.rb index edf2295..9dc89db 100644 --- a/lib/apple_auth/token.rb +++ b/lib/apple_auth/token.rb @@ -3,12 +3,12 @@ module AppleAuth class Token APPLE_AUD = 'https://appleid.apple.com' - APPLE_CONFIG = AppleAuth.config APPLE_CODE_TYPE = 'authorization_code' APPLE_ALG = 'ES256' - def initialize(code) + def initialize(code, config: AppleAuth.config) @code = code + @config = config end # :reek:FeatureEnvy @@ -21,14 +21,14 @@ def authenticate! private - attr_reader :code + attr_reader :code, :config def apple_token_params { - client_id: APPLE_CONFIG.apple_team_id, + client_id: config.apple_client_id, client_secret: client_secret_from_jwt, grant_type: APPLE_CODE_TYPE, - redirect_uri: APPLE_CONFIG.redirect_uri, + redirect_uri: config.redirect_uri, code: code } end @@ -40,18 +40,18 @@ def client_secret_from_jwt def claims time_now = Time.now.to_i { - iss: APPLE_CONFIG.apple_team_id, + iss: config.apple_team_id, iat: time_now, exp: time_now + 10.minutes.to_i, aud: APPLE_AUD, - sub: APPLE_CONFIG.apple_client_id + sub: config.apple_client_id } end def claims_headers { alg: APPLE_ALG, - kid: AppleAuth.config.apple_key_id + kid: config.apple_key_id } end @@ -62,8 +62,8 @@ def request_header end def gen_private_key - key = AppleAuth.config.apple_private_key - key = OpenSSL::PKey::EC.new(key) unless key.class == OpenSSL::PKey::EC + key = config.apple_private_key + key = OpenSSL::PKey::EC.new(key) unless key.is_a?(OpenSSL::PKey::EC) key end @@ -89,10 +89,10 @@ def reponse_hash(access_token) end def apple_access_token - client = ::OAuth2::Client.new(APPLE_CONFIG.apple_client_id, + client = ::OAuth2::Client.new(config.apple_client_id, client_secret_from_jwt, client_urls) - client.auth_code.get_token(code, { redirect_uri: APPLE_CONFIG.redirect_uri }, {}) + client.auth_code.get_token(code, { redirect_uri: config.redirect_uri }, {}) end end end