Class: ShopifyCLI::IdentityAuth::EnvAuthToken

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/identity_auth/env_auth_token.rb

Defined Under Namespace

Classes: Token

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.exchanged_partners_tokenObject

Returns the value of attribute exchanged_partners_token.



7
8
9
# File 'lib/shopify_cli/identity_auth/env_auth_token.rb', line 7

def exchanged_partners_token
  @exchanged_partners_token
end

Class Method Details

.fetch_exchanged_partners_tokenObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shopify_cli/identity_auth/env_auth_token.rb', line 13

def fetch_exchanged_partners_token
  current_time = Time.now.to_i

  # If we have an in-memory token that hasn't expired yet, we reuse it.
  if exchanged_partners_token && current_time < exchanged_partners_token.expires_at.to_i
    return exchanged_partners_token.token
  end

  new_exchanged_token = yield(Environment.auth_token)
  token = new_exchanged_token["access_token"]
  expires_in = new_exchanged_token["expires_in"].to_i
  expires_at = Time.at(current_time + expires_in)

  token = Token.new(token: token, expires_at: expires_at)

  self.exchanged_partners_token = token
  token.token
end

.partners_token_present?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/shopify_cli/identity_auth/env_auth_token.rb', line 9

def partners_token_present?
  Environment.auth_token
end