class OAuth2::AccessToken
def initialize(client, token, opts = {})
(**opts)
-
:param_name
(String
) -- the parameter name to use for transmission of the -
:header_format
(String
) -- the string format to use for the Authorization header -
:mode
(Symbol
) -- the transmission mode of the Access Token parameter value -
:expires_latency
(FixNum, String
) -- the number of seconds by which AccessToken validity will be reduced to offset latency, @version 2.0+ -
:expires_at
(FixNum, String
) -- the epoch time in seconds in which AccessToken will expire -
:expires_in
(FixNum, String
) -- the number of seconds in which the AccessToken will expire -
:refresh_token
(String
) -- the refresh_token value
Parameters:
-
opts
(Hash
) -- the options to create the Access Token with -
token
(String
) -- the Access Token value (optional, may not be used in refresh flows) -
client
(Client
) -- the OAuth2::Client instance
def initialize(client, token, opts = {}) @client = client @token = token.to_s opts = opts.dup %i[refresh_token expires_in expires_at expires_latency].each do |arg| instance_variable_set("@#{arg}", opts.delete(arg) || opts.delete(arg.to_s)) end no_tokens = (@token.nil? || @token.empty?) && (@refresh_token.nil? || @refresh_token.empty?) if no_tokens if @client.options[:raise_errors] error = Error.new(opts) raise(error) else warn('OAuth2::AccessToken has no token') end end # @option opts [Fixnum, String] :expires is deprecated @expires_in ||= opts.delete('expires') @expires_in &&= @expires_in.to_i @expires_at &&= convert_expires_at(@expires_at) @expires_latency &&= @expires_latency.to_i @expires_at ||= Time.now.to_i + @expires_in if @expires_in @expires_at -= @expires_latency if @expires_latency @options = {mode: opts.delete(:mode) || :header, header_format: opts.delete(:header_format) || 'Bearer %s', param_name: opts.delete(:param_name) || 'access_token'} @params = opts end