Sha256: 0940f24da9bcb5cb2d0081f9e06e2cbbadb3845941ea2bdba3ef820a45820ba6
Contents?: true
Size: 871 Bytes
Versions: 7
Compression:
Stored size: 871 Bytes
Contents
require 'openssl' require 'jwt' module ConnectorKit # Helper class for generating JWT tokens class TokenGenerator def self.cretat_from_file(issuer_id, key_id, private_key_file_path) private_key = File.read(@private_key_file_path) instance = TokenGenerator.new(issuer_id, key_id, private_key) end def initialize(issuer_id, key_id, private_key) @private_key = private_key @custom_headers = { kid: key_id, typ: 'JWT' } @payload = { iss: issuer_id, aud: 'appstoreconnect-v1' } end def generate_token ecdsa_key = OpenSSL::PKey.read(@private_key) expiration = Time.now.to_i + 20 * 60 @payload[:exp] = expiration puts "Generated token expires: #{Time.at(expiration)}" JWT.encode(@payload, ecdsa_key, 'ES256', @custom_headers) end end end
Version data entries
7 entries across 7 versions & 2 rubygems