Sha256: 757b373f8a3feda315973463997dba7dac84779c05fc9bef14d681dad55126da

Contents?: true

Size: 631 Bytes

Versions: 6

Compression:

Stored size: 631 Bytes

Contents

# frozen_string_literal: true

module AppStoreConnect
  class Authorization
    AUDIENCE = 'appstoreconnect-v1'
    ALGORITHM = 'ES256'

    attr_reader :key_id, :issuer_id, :private_key

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

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

    def header_fields
      { kid: key_id }
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
app_store_connect-0.10.0 lib/app_store_connect/authorization.rb
app_store_connect-0.9.0 lib/app_store_connect/authorization.rb
app_store_connect-0.8.0 lib/app_store_connect/authorization.rb
app_store_connect-0.7.0 lib/app_store_connect/authorization.rb
app_store_connect-0.6.0 lib/app_store_connect/authorization.rb
app_store_connect-0.5.0 lib/app_store_connect/authorization.rb