Class: Payabli::Internal::OAuthProvider
- Inherits:
-
Object
- Object
- Payabli::Internal::OAuthProvider
- Defined in:
- lib/payabli/internal/oauth_provider.rb
Constant Summary collapse
- BUFFER_IN_SECONDS =
2 minutes
120
Instance Method Summary collapse
-
#auth_headers ⇒ Hash[String, String]
Returns the authentication headers to be included in requests.
- #initialize(auth_client:, options:) ⇒ void constructor
-
#token ⇒ String
Returns a cached access token, refreshing if necessary.
Constructor Details
#initialize(auth_client:, options:) ⇒ void
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 = @access_token = nil @expires_at = nil end |
Instance Method Details
#auth_headers ⇒ Hash[String, String]
Returns the authentication headers to be included in requests.
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 |
#token ⇒ String
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.
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 |