|
3 | 3 | module OmniAuth
|
4 | 4 | module Strategies
|
5 | 5 | class Slack < OmniAuth::Strategies::OAuth2
|
| 6 | + option :name, 'slack' |
6 | 7 |
|
7 |
| - option :name, "slack" |
8 |
| - |
9 |
| - option :authorize_options, [ :scope, :team ] |
| 8 | + option :authorize_options, [:scope, :team] |
10 | 9 |
|
11 | 10 | 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' |
14 | 13 | }
|
15 | 14 |
|
16 | 15 | option :auth_token_params, {
|
@@ -43,19 +42,36 @@ class Slack < OmniAuth::Strategies::OAuth2
|
43 | 42 | end
|
44 | 43 |
|
45 | 44 | 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 |
47 | 55 | end
|
48 | 56 |
|
49 | 57 | def user_info
|
50 | 58 | @user_info ||= access_token.get("/api/users.info?user=#{raw_info['user_id']}").parsed
|
51 | 59 | end
|
52 | 60 |
|
53 | 61 | def team_info
|
54 |
| - @team_info ||= access_token.get("/api/team.info").parsed |
| 62 | + @team_info ||= access_token.get('/api/team.info').parsed |
55 | 63 | end
|
56 | 64 |
|
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? |
59 | 75 | end
|
60 | 76 | end
|
61 | 77 | end
|
|
0 commit comments