Sha256: a5615c46280ce7e6deb31c2ef7cb22fe9eb0885cbcddd72febb0886384185f57

Contents?: true

Size: 768 Bytes

Versions: 23

Compression:

Stored size: 768 Bytes

Contents

# frozen_string_literal: true

require 'jwt'

module AppStoreConnect
  class Client
    class Authorization
      OPTIONS = %i[key_id issuer_id private_key].freeze

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

      attr_reader(*OPTIONS)

      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

      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
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
app_store_connect-0.38.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.37.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.36.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.35.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.34.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.33.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.32.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.30.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.29.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.28.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.27.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.26.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.25.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.23.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.22.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.21.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.20.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.19.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.18.0 lib/app_store_connect/client/authorization.rb
app_store_connect-0.17.0 lib/app_store_connect/client/authorization.rb