Class: ADAL::SuccessResponse
- Inherits:
-
TokenResponse
- Object
- TokenResponse
- ADAL::SuccessResponse
- Includes:
- Logging
- Defined in:
- lib/adal/token_response.rb
Overview
A token response that contains an access token. All fields are read only and may be nil. Some fields are only populated in certain flows.
Constant Summary collapse
- OAUTH_FIELDS =
These fields may or may not be included in the response from the token endpoint.
[:access_token, :expires_in, :expires_on, :id_token, :not_before, :refresh_token, :resource, :scope, :token_type]
Constants included from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::DEFAULT_LOG_OUTPUT
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#user_info ⇒ Object
readonly
Returns the value of attribute user_info.
Instance Method Summary collapse
-
#initialize(fields = {}) ⇒ SuccessResponse
constructor
Constructs a SuccessResponse from a collection of fields returned from a token endpoint.
-
#parse_id_token(id_token) ⇒ Object
Parses the raw id token into an ADAL::UserInformation.
-
#to_json(_ = nil) ⇒ Object
Converts the fields that were used to create this token response into a JSON string.
Methods included from Logging
Methods inherited from TokenResponse
Constructor Details
#initialize(fields = {}) ⇒ SuccessResponse
Constructs a SuccessResponse from a collection of fields returned from a token endpoint.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/adal/token_response.rb', line 82 def initialize(fields = {}) @fields = fields fields.each { |k, v| instance_variable_set("@#{k}", v) } parse_id_token(id_token) @expires_on = @expires_in.to_i + Time.now.to_i logger.info('Parsed a SuccessResponse with access token digest ' \ "#{Digest::SHA256.hexdigest @access_token.to_s} and " \ 'refresh token digest ' \ "#{Digest::SHA256.hexdigest @refresh_token.to_s}.") end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
75 76 77 |
# File 'lib/adal/token_response.rb', line 75 def fields @fields end |
#user_info ⇒ Object (readonly)
Returns the value of attribute user_info.
74 75 76 |
# File 'lib/adal/token_response.rb', line 74 def user_info @user_info end |
Instance Method Details
#parse_id_token(id_token) ⇒ Object
Parses the raw id token into an ADAL::UserInformation. If the id token is missing, an ADAL::UserInformation will still be generated, it just won’t contain any displayable information.
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/adal/token_response.rb', line 113 def parse_id_token(id_token) if id_token.nil? logger.warn('No id token found.') @user_info ||= ADAL::UserInformation.new(unique_id: SecureRandom.uuid) return end logger.verbose('Attempting to decode id token in token response.') claims = JWT.decode(id_token.to_s, nil, false).first @id_token = id_token @user_info = ADAL::UserInformation.new(claims) end |
#to_json(_ = nil) ⇒ Object
Converts the fields that were used to create this token response into a JSON string. This is helpful for storing then in a database.
101 102 103 |
# File 'lib/adal/token_response.rb', line 101 def to_json(_ = nil) JSON.unparse(fields) end |