Class: Bosh::Cli::Client::Uaa::AccessInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/client/uaa/access_info.rb

Direct Known Subclasses

ClientAccessInfo, PasswordAccessInfo

Constant Summary collapse

EXPIRATION_DEADLINE_IN_SECONDS =
30

Instance Method Summary collapse

Constructor Details

#initialize(token_info, token_decoder) ⇒ AccessInfo

Returns a new instance of AccessInfo.



8
9
10
11
# File 'lib/cli/client/uaa/access_info.rb', line 8

def initialize(token_info, token_decoder)
  @token_info = token_info
  @token_decoder = token_decoder
end

Instance Method Details

#auth_headerObject



13
14
15
# File 'lib/cli/client/uaa/access_info.rb', line 13

def auth_header
  @token_info.auth_header
end

#expires_soon?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/cli/client/uaa/access_info.rb', line 25

def expires_soon?
  expiration = token_data[:exp] || token_data['exp']
  (Time.at(expiration).to_i - Time.now.to_i) < EXPIRATION_DEADLINE_IN_SECONDS
end

#refresh_tokenObject



17
18
19
# File 'lib/cli/client/uaa/access_info.rb', line 17

def refresh_token
  @token_info.info[:refresh_token] || @token_info.info['refresh_token']
end

#to_hashObject



34
35
36
37
38
39
# File 'lib/cli/client/uaa/access_info.rb', line 34

def to_hash
  {
    'access_token' => auth_header,
    'refresh_token' => refresh_token
  }
end

#token_dataObject



30
31
32
# File 'lib/cli/client/uaa/access_info.rb', line 30

def token_data
  @token_data ||= @token_decoder.decode(@token_info)
end

#was_issued_for?(other_username) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cli/client/uaa/access_info.rb', line 21

def was_issued_for?(other_username)
  username == other_username
end