class ADAL::SuccessResponse
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.
Constants
- OAUTH_FIELDS
These fields may or may not be included in the response from the token endpoint.
Attributes
fields[R]
user_info[R]
Public Class Methods
new(fields = {})
click to toggle source
Constructs a SuccessResponse
from a collection of fields returned from a token endpoint.
@param Hash
# 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
Public Instance Methods
parse_id_token(id_token)
click to toggle source
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.
@param String id_token
The id token to parse Adds an id token to the token response if one is not present
# 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)
click to toggle source
Converts the fields that were used to create this token response into a JSON string. This is helpful for storing then in a database.
@param JSON::Ext::Generator::State
We don't care about this, because the JSON representation of this object does not depend on the fields before it.
@return String
# File lib/adal/token_response.rb, line 101 def to_json(_ = nil) JSON.unparse(fields) end