Class: Payabli::Internal::OAuthProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/payabli/internal/oauth_provider.rb

Constant Summary collapse

BUFFER_IN_SECONDS =

2 minutes

120

Instance Method Summary collapse

Constructor Details

#initialize(auth_client:, options:) ⇒ void

Parameters:

  • auth_client (untyped)
  • options (Hash[String, untyped])


12
13
14
15
16
17
# File 'lib/payabli/internal/oauth_provider.rb', line 12

def initialize(auth_client:, options:)
  @auth_client = auth_client
  @options = options
  @access_token = nil
  @expires_at = nil
end

Instance Method Details

#auth_headersHash[String, String]

Returns the authentication headers to be included in requests.

Returns:

  • (Hash[String, String])


32
33
34
35
36
37
# File 'lib/payabli/internal/oauth_provider.rb', line 32

def auth_headers
  access_token = token
  {
    Authorization: "Bearer #{access_token}"
  }
end

#tokenString

Returns a cached access token, refreshing if necessary. Refreshes the token if it's nil, or if we're within the buffer period before expiration.

Returns:

  • (String)


23
24
25
26
27
# File 'lib/payabli/internal/oauth_provider.rb', line 23

def token
  return refresh if @access_token.nil? || token_needs_refresh?

  @access_token
end