Class: OCI::Auth::SecurityTokenContainer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#jwtObject (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_tokenObject (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

Returns:

  • (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

Returns:

  • (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