Class: AppStoreConnect::Authorization

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

Constant Summary collapse

AUDIENCE =
'appstoreconnect-v1'
ALGORITHM =
'ES256'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_id:, issuer_id:, private_key:) ⇒ Authorization

Returns a new instance of Authorization.



12
13
14
15
16
# File 'lib/app_store_connect/authorization.rb', line 12

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

Instance Attribute Details

#issuer_idObject (readonly)

Returns the value of attribute issuer_id.



10
11
12
# File 'lib/app_store_connect/authorization.rb', line 10

def issuer_id
  @issuer_id
end

#key_idObject (readonly)

Returns the value of attribute key_id.



10
11
12
# File 'lib/app_store_connect/authorization.rb', line 10

def key_id
  @key_id
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



10
11
12
# File 'lib/app_store_connect/authorization.rb', line 10

def private_key
  @private_key
end

Instance Method Details

#header_fieldsObject



26
27
28
# File 'lib/app_store_connect/authorization.rb', line 26

def header_fields
  { kid: key_id }
end

#payloadObject



18
19
20
21
22
23
24
# File 'lib/app_store_connect/authorization.rb', line 18

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

#tokenObject



30
31
32
# File 'lib/app_store_connect/authorization.rb', line 30

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