Class: OCI::Auth::SecurityTokenContainer
- Inherits:
-
Object
- Object
- OCI::Auth::SecurityTokenContainer
- Defined in:
- lib/oci/auth/security_token_container.rb
Overview
A container class which holds the raw token retrieved from Auth Service and its decoded equivalent
Instance Attribute Summary collapse
-
#jwt ⇒ Object
readonly
Returns the value of attribute jwt.
-
#security_token ⇒ Object
readonly
Returns the value of attribute security_token.
Instance Method Summary collapse
-
#initialize(security_token, key_pair: nil) ⇒ SecurityTokenContainer
constructor
A new instance of SecurityTokenContainer.
- #token_valid? ⇒ Boolean
- #token_valid_with_half_expiration_time? ⇒ Boolean
Constructor Details
#initialize(security_token, key_pair: nil) ⇒ SecurityTokenContainer
Returns a new instance of SecurityTokenContainer.
14 15 16 17 18 |
# File 'lib/oci/auth/security_token_container.rb', line 14 def initialize(security_token, key_pair: nil) @key_pair = key_pair @security_token = security_token @jwt = JWT.decode(@security_token, nil, false) end |
Instance Attribute Details
#jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
11 12 13 |
# File 'lib/oci/auth/security_token_container.rb', line 11 def jwt @jwt end |
#security_token ⇒ Object (readonly)
Returns the value of attribute security_token.
12 13 14 |
# File 'lib/oci/auth/security_token_container.rb', line 12 def security_token @security_token end |
Instance Method Details
#token_valid? ⇒ Boolean
20 21 22 23 |
# File 'lib/oci/auth/security_token_container.rb', line 20 def token_valid? expiration_epoch_seconds = @jwt[0]['exp'] expiration_epoch_seconds > Time.now.to_i end |
#token_valid_with_half_expiration_time? ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/oci/auth/security_token_container.rb', line 25 def token_valid_with_half_expiration_time? issue_epoch_seconds = @jwt[0]['iat'] expiration_epoch_seconds = @jwt[0]['exp'] half_valid_duration = (expiration_epoch_seconds - issue_epoch_seconds) / 2 (expiration_epoch_seconds - half_valid_duration) > Time.now.to_i end |