Class: Cosmos::CosmosKeycloakAuthentication
- Inherits:
-
CosmosAuthentication
- Object
- CosmosAuthentication
- Cosmos::CosmosKeycloakAuthentication
- Defined in:
- lib/cosmos/utilities/authentication.rb
Overview
Cosmos enterprise Keycloak authentication code
Instance Method Summary collapse
-
#initialize(url) ⇒ CosmosKeycloakAuthentication
constructor
A new instance of CosmosKeycloakAuthentication.
-
#token ⇒ Object
Load the token from the environment.
Constructor Details
#initialize(url) ⇒ CosmosKeycloakAuthentication
Returns a new instance of CosmosKeycloakAuthentication.
59 60 61 62 63 64 65 66 67 |
# File 'lib/cosmos/utilities/authentication.rb', line 59 def initialize(url) @url = url @auth_mutex = Mutex.new @refresh_token = nil @expires_at = nil @refresh_expires_at = nil @token = nil @log = [nil, nil] end |
Instance Method Details
#token ⇒ Object
Load the token from the environment
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cosmos/utilities/authentication.rb', line 70 def token() @auth_mutex.synchronize do @log = [nil, nil] current_time = Time.now.to_i if @token.nil? _make_token(current_time) elsif @refresh_expires_at < current_time _make_token(current_time) elsif @expires_at < current_time _refresh_token(current_time) end end "Bearer #{@token}" end |