Class: AppStoreDevApi::Client::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/app_store_dev_api/client/authorization.rb

Constant Summary collapse

OPTIONS =
%i[key_id issuer_id private_key].freeze
AUDIENCE =
'appstoreconnect-v1'
ALGORITHM =
'ES256'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Authorization

Returns a new instance of Authorization.



15
16
17
18
19
# File 'lib/app_store_dev_api/client/authorization.rb', line 15

def initialize(options)
  @key_id = options.fetch(:key_id)
  @issuer_id = options.fetch(:issuer_id)
  @private_key = OpenSSL::PKey.read(options.fetch(:private_key))
end

Instance Method Details

#header_fieldsObject



29
30
31
# File 'lib/app_store_dev_api/client/authorization.rb', line 29

def header_fields
  { kid: key_id }
end

#payloadObject



21
22
23
24
25
26
27
# File 'lib/app_store_dev_api/client/authorization.rb', line 21

def payload
  {
    exp: Time.now.to_i + 20 * 60,
    iss: issuer_id,
    aud: AUDIENCE
  }
end

#tokenObject



33
34
35
# File 'lib/app_store_dev_api/client/authorization.rb', line 33

def token
  JWT.encode(payload, private_key, ALGORITHM, header_fields)
end