Class: Spaceship::ConnectAPI::Token
- Inherits:
-
Object
- Object
- Spaceship::ConnectAPI::Token
- Defined in:
- spaceship/lib/spaceship/connect_api/token.rb
Constant Summary collapse
- MAX_TOKEN_DURATION =
maximum expiration supported by AppStore (20 minutes)
1200
Instance Attribute Summary collapse
-
#issuer_id ⇒ Object
readonly
Returns the value of attribute issuer_id.
-
#key_id ⇒ Object
readonly
Returns the value of attribute key_id.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(key_id: nil, issuer_id: nil, key: nil) ⇒ Token
constructor
A new instance of Token.
Constructor Details
#initialize(key_id: nil, issuer_id: nil, key: nil) ⇒ Token
Returns a new instance of Token.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'spaceship/lib/spaceship/connect_api/token.rb', line 32 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 |
Instance Attribute Details
#issuer_id ⇒ Object (readonly)
Returns the value of attribute issuer_id.
17 18 19 |
# File 'spaceship/lib/spaceship/connect_api/token.rb', line 17 def issuer_id @issuer_id end |
#key_id ⇒ Object (readonly)
Returns the value of attribute key_id.
16 17 18 |
# File 'spaceship/lib/spaceship/connect_api/token.rb', line 16 def key_id @key_id end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
18 19 20 |
# File 'spaceship/lib/spaceship/connect_api/token.rb', line 18 def text @text end |
Class Method Details
.create(key_id: nil, issuer_id: nil, filepath: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'spaceship/lib/spaceship/connect_api/token.rb', line 20 def self.create(key_id: nil, issuer_id: nil, filepath: nil) key_id ||= ENV['SPACESHIP_CONNECT_API_KEY_ID'] issuer_id ||= ENV['SPACESHIP_CONNECT_API_ISSUER_ID'] filepath ||= ENV['SPACESHIP_CONNECT_API_KEY_FILEPATH'] self.new( key_id: key_id, issuer_id: issuer_id, key: OpenSSL::PKey::EC.new(File.read(filepath)) ) end |
Instance Method Details
#expired? ⇒ Boolean
51 52 53 |
# File 'spaceship/lib/spaceship/connect_api/token.rb', line 51 def expired? @expiration < Time.now end |