class OmniAuth::Strategies::Slack
This is the OmniAuth
strategy for Slack
. It is used as Rack middleware.
use OmniAuth::Builder do provider :slack, OAUTH_KEY, OAUTH_SECRET, options... end
Constants
- AUTH_OPTIONS
Master list of authorization options handled by omniauth-slack. See below for redirect_uri.
Public Instance Methods
Gets main access_token, if valid, otherwise gets user_token
, if valid. Handles Slack
v1 and v2 API (v2 is non-conformant with OAUTH2 spec).
# File lib/omniauth/strategies/slack.rb, line 256 def access_or_user_token if access_token&.token access_token elsif user_token user_token else access_token end end
Returns¶ ↑
Returns OmniAuth::Slack::AuthHash
Super result is converted to plain hash first, so AuthHash can do its recursive build magic.
# File lib/omniauth/strategies/slack.rb, line 171 def auth_hash OmniAuth::Slack::AuthHash.new super.to_hash end
Pre-sets env vars for super.
OmniAuth
callback phase to extract session var for omniauth.authorize_params into env (this is how omniauth does this).
# File lib/omniauth/strategies/slack.rb, line 159 def callback_phase #(*args) # This technique copied from OmniAuth::Strategy, # (this is how they do it for other omniauth objects). env['omniauth.authorize_params'] = session.delete('omniauth.authorize_params') super end
Dropping query_string from the default OmniAuth
callback_url
prevents some errors in call to /api/oauth.[v2.]access.
# File lib/omniauth/strategies/slack.rb, line 198 def callback_url options.redirect_uri || full_host + script_name + callback_path end
Uses `OmniAuth::Slack::OAuth2::Client` to handle Slack-specific features.
* Logs API requests with OmniAuth.logger. * Allows passthrough of Slack
team_domain. * Enables/disables Client instance history. * Allows use of OmniAuth::Slack::OAuth2::AccessToken
.
Returns¶ ↑
Returns instance of OmniAuth::Slack::OAuth2::Client
.
# File lib/omniauth/strategies/slack.rb, line 184 def client @client ||= ( team_domain = (pass_through_params.include?('team_domain') && request.params['team_domain']) ? request.params['team_domain'] : options.team_domain new_client = OmniAuth::Slack::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options.merge({subdomain:team_domain}))) debug{"Strategy #{self} using Client #{new_client} with callback_url #{callback_url}"} new_client ) end
Gets and decodes :pass_through_params option.
# File lib/omniauth/strategies/slack.rb, line 215 def pass_through_params ptp = [options.pass_through_params].flatten.compact case when ptp[0].to_s == 'all' options.pass_through_params = AUTH_OPTIONS when ptp[0].to_s == 'none' [] else ptp end end
Points to client @history, which is filled with API response objects.
# File lib/omniauth/strategies/slack.rb, line 242 def raw_info @raw_info ||= access_token.client.history debug{"Retrieved raw_info (size #{@raw_info.size}) (object_id #{@raw_info.object_id})"} @raw_info end
# File lib/omniauth/strategies/slack.rb, line 266 def scopes_requested # omniauth.authorize_params is an enhancement to omniauth functionality for omniauth-slack. out = { scope: env['omniauth.authorize_params'].to_h['scope'], user_scope: env['omniauth.authorize_params'].to_h['user_scope'] } debug{"scopes_requested: #{out}"} return out end
Gets 'authed_user' sub-token from main access token.
# File lib/omniauth/strategies/slack.rb, line 250 def user_token access_token&.user_token end