Module: AppStoreConnect::JWT::Utils

Defined in:
lib/app_store_connect/jwt/utils.rb

Class Method Summary collapse

Class Method Details

.decode(token, private_key, algorithm) ⇒ Array<Hash>

Parameters:

  • token (String)
  • private_key (OpenSSL::PKey::EC)
  • algorithm (String)

Returns:

  • (Array<Hash>)


22
23
24
# File 'lib/app_store_connect/jwt/utils.rb', line 22

def self.decode(token, private_key, algorithm)
  ::JWT.decode(token, private_key, true, algorithm: algorithm)
end

.encode(payload, private_key, algorithm, header_fields) ⇒ String

Parameters:

  • payload (Hash)
  • private_key (OpenSSL::PKey::EC)
  • algorithm (String)
  • header_fields (Hash)

Returns:

  • (String)


14
15
16
# File 'lib/app_store_connect/jwt/utils.rb', line 14

def self.encode(payload, private_key, algorithm, header_fields)
  ::JWT.encode(payload, private_key, algorithm, header_fields)
end

.header_fields(key_id) ⇒ Hash

Parameters:

  • key_id (String)

Returns:

  • (Hash)


28
29
30
# File 'lib/app_store_connect/jwt/utils.rb', line 28

def self.header_fields(key_id)
  { kid: key_id }
end

.payload(issuer_id, audience) ⇒ Hash

Parameters:

  • issuer_id (String)
  • audience (String)

Returns:

  • (Hash)


35
36
37
38
39
40
41
# File 'lib/app_store_connect/jwt/utils.rb', line 35

def self.payload(issuer_id, audience)
  {
    exp: Time.now.to_i + 20 * 60,
    iss: issuer_id,
    aud: audience
  }
end

.private_key(path) ⇒ OpenSSL::PKey::EC

Parameters:

  • path (String)

Returns:

  • (OpenSSL::PKey::EC)


45
46
47
# File 'lib/app_store_connect/jwt/utils.rb', line 45

def self.private_key(path)
  OpenSSL::PKey.read(File.read(File.expand_path(path)))
end