Sha256: e0fe523429557085ac248a39a4f1201a7c57958a7ed6dcbcdb8c1fb6ec607149

Contents?: true

Size: 954 Bytes

Versions: 25

Compression:

Stored size: 954 Bytes

Contents

require 'jwt'
require 'openssl'

# extract pem from .p8
# openssl pkcs8 -topk8 -outform PEM -in AuthKey.p8 -out key.pem -nocrypt

# compute public key
# openssl ec -in key.pem -pubout -out public_key.pem -aes256

module Spaceship
  module ConnectAPI
    class Token
      # maximum expiration supported by AppStore (20 minutes)
      MAX_TOKEN_DURATION = 1200

      attr_reader :key_id
      attr_reader :issuer_id
      attr_reader :text

      def initialize(key_id: nil, issuer_id: nil, key: nil)
        @expiration = Time.now + MAX_TOKEN_DURATION
        @key_id = key_id
        @key = key
        @issuer_id = issuer_id

        header = {
          kid: key_id
        }

        payload = {
          iss: issuer_id,
          exp: @expiration.to_i,
          aud: 'appstoreconnect-v1'
        }

        @text = JWT.encode(payload, key, 'ES256', header)
      end

      def expired?
        @expiration < Time.now
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
fastlane-2.126.0.beta.20190623200100 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190622200100 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190621200104 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190620200055 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190619200046 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190618200051 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190617200114 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190616200045 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190615200013 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190614200105 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190613200017 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190611200027 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190610200032 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190609200013 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190608200023 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190607200028 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190606200048 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190605200119 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.126.0.beta.20190604200017 spaceship/lib/spaceship/connect_api/token.rb
fastlane-2.125.2 spaceship/lib/spaceship/connect_api/token.rb