Class: X::AppOnlyAuthenticator
- Inherits:
-
Authenticator
- Object
- Authenticator
- X::AppOnlyAuthenticator
- Defined in:
- x-core/lib/x/core/app_only_authenticator.rb
Overview
Authenticates as an app with a bearer token, fetched with the API key and secret when first needed
A bearer token the API rejects with 401 Unauthorized, as it does one that was invalidated, is dropped, and the request is sent again with one fetched in its place.
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
The API key.
Instance Method Summary collapse
-
#headers(_request) ⇒ Hash{String => String}
Generate the authentication headers, fetching the bearer token first if needed.
-
#initialize(api_key:, api_key_secret:, bearer_token: nil) ⇒ AppOnlyAuthenticator
constructor
Initialize a new app-only authenticator.
Constructor Details
#initialize(api_key:, api_key_secret:, bearer_token: nil) ⇒ AppOnlyAuthenticator
Initialize a new app-only authenticator
45 46 47 48 49 50 51 52 |
# File 'x-core/lib/x/core/app_only_authenticator.rb', line 45 def initialize(api_key:, api_key_secret:, bearer_token: nil) CredentialValidator.validate_required!({api_key:, api_key_secret:}, {bearer_token:}) @api_key = api_key @api_key_secret = api_key_secret @bearer_token = bearer_token @connection, @token_url, @token_headers = Connection.new, TOKEN_URL, {} @mutex = Mutex.new end |
Instance Attribute Details
#api_key ⇒ String (readonly)
The API key
33 34 35 |
# File 'x-core/lib/x/core/app_only_authenticator.rb', line 33 def api_key @api_key end |
Instance Method Details
#headers(_request) ⇒ Hash{String => String}
Generate the authentication headers, fetching the bearer token first if needed
64 65 66 |
# File 'x-core/lib/x/core/app_only_authenticator.rb', line 64 def headers(_request) {AUTHENTICATION_HEADER => "Bearer #{bearer_token}"} end |