Class: Spotted::Internal::OAuth2ClientCredentials
- Inherits:
-
Object
- Object
- Spotted::Internal::OAuth2ClientCredentials
- Defined in:
- lib/spotted/internal/oauth2.rb
Instance Method Summary collapse
- #auth_headers ⇒ Hash{String=>String} private
-
#initialize(token_url:, client_id:, client_secret:, timeout:, client:) ⇒ OAuth2ClientCredentials
constructor
A new instance of OAuth2ClientCredentials.
Constructor Details
#initialize(token_url:, client_id:, client_secret:, timeout:, client:) ⇒ OAuth2ClientCredentials
Returns a new instance of OAuth2ClientCredentials.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/spotted/internal/oauth2.rb', line 11 def initialize(token_url:, client_id:, client_secret:, timeout:, client:) @token_url = token_url @client_id = client_id @client_secret = client_secret @client = client @timeout = timeout @token = nil @token_expires_at = nil @mutex = Thread::Mutex.new end |
Instance Method Details
#auth_headers ⇒ Hash{String=>String}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/spotted/internal/oauth2.rb', line 25 def auth_headers @mutex.synchronize do if @token && !token_expired? return {"Authorization" => "Bearer #{@token}"} end @token = nil @token_expires_at = nil token_response = fetch_token if token_response @token = token_response[:access_token] @token_expires_at = Time.now + token_response[:expires_in] return {"Authorization" => "Bearer #{@token}"} end {} end end |