class OAuth2::AccessToken

def from_hash(client, hash)

Other tags:
    Note: - If snaky key conversion is being used, token_name needs to match the converted key.
    Note: - For "soon-to-expire"/"clock-skew" functionality see the `:expires_latency` option.
    Note: - If no token keys are present, a warning will be issued unless
    Note: - If multiple token keys are present, a warning will be issued unless
    Note: - The method will use the first found token key in the following order:

Returns:
  • (OAuth2::AccessToken) - the initialized AccessToken

Options Hash: (**hash)
  • 'expires_latency' (Integer, String) -- seconds to reduce token validity by
  • 'expires_at' (Integer, String) -- epoch time in seconds when token expires
  • 'expires_in' (Integer, String) -- number of seconds until token expires
  • 'refresh_token' (String) -- the refresh token value
  • 'token' (String) -- alternative key for the access token value
  • 'id_token' (String) -- alternative key for the access token value
  • 'access_token' (String) -- the access token value

Parameters:
  • hash (Hash) -- a hash containing the token and other properties
  • client (OAuth2::Client) -- the OAuth2::Client instance
def from_hash(client, hash)
  fresh = hash.dup
  # If token_name is present, then use that key name
  key =
    if fresh.key?(:token_name)
      t_key = fresh[:token_name]
      no_tokens_warning(fresh, t_key)
      t_key
    else
      # Otherwise, if one of the supported default keys is present, use whichever has precedence
      supported_keys = TOKEN_KEY_LOOKUP & fresh.keys
      t_key = supported_keys[0]
      extra_tokens_warning(supported_keys, t_key)
      t_key
    end
  # :nocov:
  # TODO: Get rid of this branching logic when dropping Hashie < v3.2
  token = if !defined?(Hashie::VERSION) # i.e. <= "1.1.0"; the first Hashie to ship with a VERSION constant
    warn("snaky_hash and oauth2 will drop support for Hashie v0 in the next major version. Please upgrade to a modern Hashie.")
    # There is a bug in Hashie v0, which is accounts for.
    fresh.delete(key) || fresh[key] || ""
  else
    fresh.delete(key) || ""
  end
  # :nocov:
  new(client, token, fresh)
end