Skip to content

Commit c086cac

Browse files
author
Gustavo Bazan
committed
Add extra infor for when scope is incoming-webhook
Slack just added a new scope that allows easy creation of incoming webhooks on authorization, this changes to the strategy allows it to return the new info slack provides to the client about the created webhook
1 parent 1537dfb commit c086cac

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ test/tmp
1616
test/version_tmp
1717
tmp
1818
.idea/
19+
.ruby-version
20+
.ruby-gemset

lib/omniauth-slack.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
require 'omniauth-slack/version'
2-
require 'omniauth/strategies/slack'
2+
require 'omniauth/strategies/slack'

lib/omniauth/strategies/slack.rb

+25-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
module OmniAuth
44
module Strategies
55
class Slack < OmniAuth::Strategies::OAuth2
6+
option :name, 'slack'
67

7-
option :name, "slack"
8-
9-
option :authorize_options, [ :scope, :team ]
8+
option :authorize_options, [:scope, :team]
109

1110
option :client_options, {
12-
site: "https://slack.com",
13-
token_url: "/api/oauth.access"
11+
site: 'https://slack.com',
12+
token_url: '/api/oauth.access'
1413
}
1514

1615
option :auth_token_params, {
@@ -43,19 +42,36 @@ class Slack < OmniAuth::Strategies::OAuth2
4342
end
4443

4544
extra do
46-
{:raw_info => raw_info, :user_info => user_info, :team_info => team_info}
45+
{
46+
raw_info: raw_info,
47+
user_info: user_info,
48+
team_info: team_info,
49+
web_hook_info: web_hook_info
50+
}
51+
end
52+
53+
def raw_info
54+
@raw_info ||= access_token.get('/api/auth.test').parsed
4755
end
4856

4957
def user_info
5058
@user_info ||= access_token.get("/api/users.info?user=#{raw_info['user_id']}").parsed
5159
end
5260

5361
def team_info
54-
@team_info ||= access_token.get("/api/team.info").parsed
62+
@team_info ||= access_token.get('/api/team.info').parsed
5563
end
5664

57-
def raw_info
58-
@raw_info ||= access_token.get("/api/auth.test").parsed
65+
def web_hook_info
66+
return {} unless incoming_webhook_allowed?
67+
access_token.params['incoming_webhook']
68+
end
69+
70+
def incoming_webhook_allowed?
71+
return false unless options['scope']
72+
webhooks_scopes = ['incoming-webhook']
73+
scopes = options['scope'].split(',')
74+
(scopes & webhooks_scopes).any?
5975
end
6076
end
6177
end

0 commit comments

Comments
 (0)