Class: OmniAuth::Strategies::Slack

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/slack.rb

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject

Pass on certain authorize_params to the Slack authorization GET request. See github.com/omniauth/omniauth/issues/390



153
154
155
156
157
158
159
160
161
# File 'lib/omniauth/strategies/slack.rb', line 153

def authorize_params
  super.tap do |params|
    %w(scope team redirect_uri).each do |v|
      if !request.params[v].to_s.empty?
        params[v.to_sym] = request.params[v]
      end
    end
  end
end

#callback_urlObject

Dropping query_string from callback_url prevents some errors in call to /api/oauth.access.



187
188
189
# File 'lib/omniauth/strategies/slack.rb', line 187

def callback_url
  full_host + script_name + callback_path
end

#clientObject

Get a new OAuth2::Client and define custom capabilities.

  • verrides super :client method.

  • Log API requests with OmniAuth.logger

  • Add API responses to @raw_info hash



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/omniauth/strategies/slack.rb', line 169

def client
  st_raw_info = raw_info
  new_client = super
  log(:debug, "New client #{new_client}.")
  
  new_client.instance_eval do
    define_singleton_method(:request) do |*args|
      OmniAuth.logger.send(:debug, "(slack) API request #{args[0..1]}; in thread #{Thread.current.object_id}.")
      request_output = super(*args)
      uri = args[1].to_s.gsub(/^.*\/([^\/]+)/, '\1') # use single-quote or double-back-slash for replacement.
      st_raw_info[uri.to_s]= request_output
      request_output
    end
  end
  new_client
end

#identityObject



191
192
193
194
195
196
197
# File 'lib/omniauth/strategies/slack.rb', line 191

def identity
  return {} unless !skip_info? && has_scope?(identity: ['identity.basic','identity:read:user']) && is_not_excluded?
  semaphore.synchronize {
    @identity_raw ||= access_token.get('/api/users.identity', headers: {'X-Slack-User' => user_id})
    @identity ||= @identity_raw.parsed
  }
end