Class: StatelyDB::Common::Auth::AuthTokenProvider
- Inherits:
-
TokenProvider
- Object
- TokenProvider
- StatelyDB::Common::Auth::AuthTokenProvider
- Defined in:
- lib/common/auth/auth_token_provider.rb
Overview
AuthTokenProvider is an implementation of the TokenProvider abstract base class which vends tokens from the StatelyDB auth API. It will default to using the value of ‘STATELY_ACCESS_KEY` if no credentials are explicitly passed and will throw an error if no credentials are found.
Defined Under Namespace
Classes: Actor, TokenState
Instance Method Summary collapse
-
#close ⇒ Object
Close the token provider and kill any background operations This just invokes the close method on the actor which should do the cleanup.
-
#get_token(force: false) ⇒ String
Get the current access token.
-
#initialize(origin: "https://api.stately.cloud", access_key: ENV.fetch("STATELY_ACCESS_KEY", nil), base_retry_backoff_secs: 1) ⇒ AuthTokenProvider
constructor
A new instance of AuthTokenProvider.
Constructor Details
#initialize(origin: "https://api.stately.cloud", access_key: ENV.fetch("STATELY_ACCESS_KEY", nil), base_retry_backoff_secs: 1) ⇒ AuthTokenProvider
Returns a new instance of AuthTokenProvider.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/common/auth/auth_token_provider.rb', line 30 def initialize( origin: "https://api.stately.cloud", access_key: ENV.fetch("STATELY_ACCESS_KEY", nil), base_retry_backoff_secs: 1 ) super() @actor = Async::Actor.new(Actor.new(origin: origin, access_key: access_key, base_retry_backoff_secs: base_retry_backoff_secs)) # this initialization cannot happen in the constructor because it is async and must run on the event loop # which is not available in the constructor @actor.init end |
Instance Method Details
#close ⇒ Object
Close the token provider and kill any background operations This just invokes the close method on the actor which should do the cleanup
45 46 47 |
# File 'lib/common/auth/auth_token_provider.rb', line 45 def close @actor.close end |
#get_token(force: false) ⇒ String
Get the current access token
51 52 53 |
# File 'lib/common/auth/auth_token_provider.rb', line 51 def get_token(force: false) @actor.get_token(force: force) end |