Class: Sorcery::Providers::Slack

Inherits:
Base
  • Object
show all
Includes:
Sorcery::Protocols::Oauth2
Defined in:
lib/sorcery/providers/slack.rb

Overview

This class adds support for OAuth with slack.com.

Instance Attribute Summary collapse

Attributes inherited from Base

#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping

Instance Method Summary collapse

Methods included from Sorcery::Protocols::Oauth2

#authorize_url, #build_client, #get_access_token, #oauth_version

Methods inherited from Base

#auth_hash, descendants, #has_callback?, name

Constructor Details

#initializeSlack

Returns a new instance of Slack.



10
11
12
13
14
15
16
17
18
# File 'lib/sorcery/providers/slack.rb', line 10

def initialize
  super

  @scope          = 'identity.basic, identity.email'
  @site           = 'https://slack.com/'
  @user_info_path = 'https://slack.com/api/users.identity'
  @auth_path      = '/oauth/authorize'
  @token_url      = '/api/oauth.access'
end

Instance Attribute Details

#auth_pathObject

Returns the value of attribute auth_path.



8
9
10
# File 'lib/sorcery/providers/slack.rb', line 8

def auth_path
  @auth_path
end

#scopeObject

Returns the value of attribute scope.



8
9
10
# File 'lib/sorcery/providers/slack.rb', line 8

def scope
  @scope
end

#token_urlObject

Returns the value of attribute token_url.



8
9
10
# File 'lib/sorcery/providers/slack.rb', line 8

def token_url
  @token_url
end

#user_info_pathObject

Returns the value of attribute user_info_path.



8
9
10
# File 'lib/sorcery/providers/slack.rb', line 8

def 
  @user_info_path
end

Instance Method Details

#get_user_hash(access_token) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/sorcery/providers/slack.rb', line 20

def get_user_hash(access_token)
  response = access_token.get()
  auth_hash(access_token).tap do |h|
    h[:user_info] = JSON.parse(response.body)
    h[:user_info]['email'] = h[:user_info]['user']['email']
    h[:uid] = h[:user_info]['user']['id']
  end
end

#login_url(_params, _session) ⇒ Object

calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.



31
32
33
# File 'lib/sorcery/providers/slack.rb', line 31

def (_params, _session)
  authorize_url(authorize_url: auth_path)
end

#process_callback(params, _session) ⇒ Object

tries to login the user from access token



36
37
38
39
40
41
42
# File 'lib/sorcery/providers/slack.rb', line 36

def process_callback(params, _session)
  args = {}.tap do |a|
    a[:code] = params[:code] if params[:code]
  end

  get_access_token(args, token_url: token_url, token_method: :post)
end