Class: OpenC3::OpenC3KeycloakAuthentication
- Inherits:
-
OpenC3Authentication
- Object
- OpenC3Authentication
- OpenC3::OpenC3KeycloakAuthentication
- Defined in:
- lib/openc3/utilities/authentication.rb
Overview
OpenC3 enterprise Keycloak authentication code
Constant Summary collapse
- REFRESH_OFFSET_SECONDS =
"access_token": "", "expires_in": 600, "refresh_expires_in": 1800, "refresh_token": "", "token_type": "bearer", "id_token": "", "not-before-policy": 0, "session_state": "", "scope": "openid email profile"
60
Instance Attribute Summary collapse
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
Instance Method Summary collapse
- #get_token_from_refresh_token(refresh_token) ⇒ Object
-
#initialize(url) ⇒ OpenC3KeycloakAuthentication
constructor
A new instance of OpenC3KeycloakAuthentication.
-
#token ⇒ Object
Load the token from the environment.
Constructor Details
#initialize(url) ⇒ OpenC3KeycloakAuthentication
Returns a new instance of OpenC3KeycloakAuthentication.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/openc3/utilities/authentication.rb', line 66 def initialize(url) @url = url @auth_mutex = Mutex.new @refresh_token = nil @expires_at = nil @refresh_expires_at = nil @token = nil @log = [nil, nil] @http = Faraday.new end |
Instance Attribute Details
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
63 64 65 |
# File 'lib/openc3/utilities/authentication.rb', line 63 def refresh_token @refresh_token end |
Instance Method Details
#get_token_from_refresh_token(refresh_token) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/openc3/utilities/authentication.rb', line 93 def get_token_from_refresh_token(refresh_token) current_time = Time.now.to_i begin @refresh_token = refresh_token _refresh_token(current_time) return @token rescue OpenC3AuthenticationError return nil end end |
#token ⇒ Object
Load the token from the environment
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/openc3/utilities/authentication.rb', line 78 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 |