class OmniAuth::Slack::OAuth2::Client

Constants

HISTORY_DEFAULT

If this is an array, request history will be stored. Only store request history if each Client instance is relatively short-lived.

From your app, you can set this:

OmniAuth::Slack::OAuth2::Client::HISTORY_DEFAULT ||= []

Then, in your authorization callback action, you can direct the OAuth2::Client request history to the AuthHash#['raw_info']:

@auth_hash = env['omniauth.auth']
@access_token = env['omniauth.strategy'].access_token
@access_token.client.history = @auth_hash.extra.raw_info

TODO: The above seems a little messy. Maybe use a proc

to rediredct Client request history to wherever.
Or maybe don't offer any history storage at all.
SUBDOMAIN_DEFAULT

Attributes

history[RW]
logger[RW]
subdomain[RW]

Public Class Methods

new(*args, **options) click to toggle source
Calls superclass method
# File lib/omniauth-slack/oauth2/client.rb, line 39
def initialize(*args, **options)
  debug{"args: #{args}"}
  super
  self.logger = OmniAuth.logger
  self.history ||= (options[:history] || HISTORY_DEFAULT)
  # Moved 'dup' to it's own line, cuz we can't dup nil in older ruby version.
  self.history && self.history = self.history.dup
  self.subdomain ||= options[:subdomain] || SUBDOMAIN_DEFAULT
end

Public Instance Methods

get_token(params, access_token_opts = {}, access_token_class = OmniAuth::Slack::OAuth2::AccessToken) click to toggle source

Wraps OAuth2::Client#get_token to pass in the omniauth-slack AccessToken class.

Calls superclass method
# File lib/omniauth-slack/oauth2/client.rb, line 50
def get_token(params, access_token_opts = {}, access_token_class = OmniAuth::Slack::OAuth2::AccessToken) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  debug{"params #{params}, access_token_opts #{access_token_opts}"}
  rslt = super(params, access_token_opts, access_token_class)
  debug{"Client #{self} built AccessToken #{rslt}"}
  rslt
end
request(*args) click to toggle source

Logs each API request and stores the API result in History array (if exists).

Storage can be disabled by setting client_options: {history: false}. Storage can be enabled by setting client_options: {history: Array.new}. Storage is enabled by default, when client is created from Strategy.

Calls superclass method
# File lib/omniauth-slack/oauth2/client.rb, line 64
def request(*args)
  logger.debug "(slack) API request '#{args[0..1]}'."  # in thread '#{Thread.current.object_id}'."  # by Client '#{self}'
  debug{"API request args #{args}"}
  request_output = super(*args)
  uri = args[1].to_s.gsub(/^.*\/([^\/]+)/, '\1') # use single-quote or double-back-slash for replacement.
  if history.is_a?(Array)
    debug{"Saving response to history object #{history.object_id}"}
    history << OmniAuth::Slack::AuthHash.new(
      {api_call: uri.to_s, time: Time.now, response: request_output}
    )
  end
  #debug{"API response (#{args[0..1]}) #{request_output.class}"}
  debug{"API response #{request_output.response.env.body}"}
  request_output
end
site(*args) click to toggle source

Wraps site to insert custom subdomain for API calls.

Calls superclass method
# File lib/omniauth-slack/oauth2/client.rb, line 81
def site(*args)
  if !@subdomain.to_s.empty?
    site_uri = URI.parse(super)
    site_uri.host = "#{@subdomain}.#{site_uri.host}"
    logger.debug "(slack) Oauth site uri with custom team_domain #{site_uri}"
    site_uri.to_s
  else
    super
  end
end