omniauth-slack 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f79b8e67dacdd3e9030fe66dd61bcbc78d1544da
4
- data.tar.gz: d0026c7cab03f2fefc77828b67ac3e981939280b
3
+ metadata.gz: 02f23c3432e35d13d73b6a665cd2cd80283e1a2c
4
+ data.tar.gz: 6bbfd64ec1070fd5e722368b42630419b73fee93
5
5
  SHA512:
6
- metadata.gz: 4cc4341e62ce85da1d4d7bed36f3e8f858851309e1812518466520b215ec86173413f50bcf161dba3e4c1a7b476f3fe1455248524b596bd68f34dd6f7c4dd187
7
- data.tar.gz: ab19de0c2cb9cec37898cfb0f9a42cccf3f544a98ba954e29d651ee60f3f422e5d0c301f1eb06dca2d3c97fd8bbebdb4dfd2c753fd85ca00689ad14e62090028
6
+ metadata.gz: a5ab0900cc8112a8c0fe62007eb21e6f97f3bf91e0135a5d245f35975771949ec4d0b14f765fe861332d2f0cb499aaaf429eb58e72eaa466896902c91994e9c0
7
+ data.tar.gz: 13953b8a129bc1f52f911fa3a0c8f71d355b35034f9e0a8c5189561103f109c39ca1c28c1be57d27ddb4cac059fbee1be8e55d3adcca862894e767438fdab731
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Slack
3
- VERSION = "2.2.0"
3
+ VERSION = "2.3.0"
4
4
  end
5
5
  end
@@ -1,4 +1,6 @@
1
1
  require 'omniauth/strategies/oauth2'
2
+ require 'uri'
3
+ require 'rack/utils'
2
4
 
3
5
  module OmniAuth
4
6
  module Strategies
@@ -20,34 +22,49 @@ module OmniAuth
20
22
  uid { raw_info['user_id'] }
21
23
 
22
24
  info do
23
- {
24
- name: user_info['user'].to_h['profile'].to_h['real_name_normalized'],
25
- email: user_info['user'].to_h['profile'].to_h['email'],
25
+ hash = {
26
26
  nickname: raw_info['user'],
27
- first_name: user_info['user'].to_h['profile'].to_h['first_name'],
28
- last_name: user_info['user'].to_h['profile'].to_h['last_name'],
29
- description: user_info['user'].to_h['profile'].to_h['title'],
30
- image_24: user_info['user'].to_h['profile'].to_h['image_24'],
31
- image_48: user_info['user'].to_h['profile'].to_h['image_48'],
32
- image: user_info['user'].to_h['profile'].to_h['image_192'],
33
27
  team: raw_info['team'],
34
28
  user: raw_info['user'],
35
29
  team_id: raw_info['team_id'],
36
- team_domain: team_info['team'].to_h['domain'],
37
- user_id: raw_info['user_id'],
38
- is_admin: user_info['user'].to_h['is_admin'],
39
- is_owner: user_info['user'].to_h['is_owner'],
40
- time_zone: user_info['user'].to_h['tz']
30
+ user_id: raw_info['user_id']
41
31
  }
32
+
33
+ unless skip_info?
34
+ hash.merge!(
35
+ name: user_info['user'].to_h['profile'].to_h['real_name_normalized'],
36
+ email: user_info['user'].to_h['profile'].to_h['email'],
37
+ first_name: user_info['user'].to_h['profile'].to_h['first_name'],
38
+ last_name: user_info['user'].to_h['profile'].to_h['last_name'],
39
+ description: user_info['user'].to_h['profile'].to_h['title'],
40
+ image_24: user_info['user'].to_h['profile'].to_h['image_24'],
41
+ image_48: user_info['user'].to_h['profile'].to_h['image_48'],
42
+ image: user_info['user'].to_h['profile'].to_h['image_192'],
43
+ team_domain: team_info['team'].to_h['domain'],
44
+ is_admin: user_info['user'].to_h['is_admin'],
45
+ is_owner: user_info['user'].to_h['is_owner'],
46
+ time_zone: user_info['user'].to_h['tz']
47
+ )
48
+ end
49
+
50
+ hash
42
51
  end
43
52
 
44
53
  extra do
45
- {
54
+ hash = {
46
55
  raw_info: raw_info,
47
- user_info: user_info,
48
- team_info: team_info,
49
- web_hook_info: web_hook_info
56
+ web_hook_info: web_hook_info,
57
+ bot_info: bot_info
50
58
  }
59
+
60
+ unless skip_info?
61
+ hash.merge!(
62
+ user_info: user_info,
63
+ team_info: team_info
64
+ )
65
+ end
66
+
67
+ hash
51
68
  end
52
69
 
53
70
  def raw_info
@@ -55,7 +72,11 @@ module OmniAuth
55
72
  end
56
73
 
57
74
  def user_info
58
- @user_info ||= access_token.get("/api/users.info?user=#{raw_info['user_id']}").parsed
75
+ url = URI.parse("/api/users.info")
76
+ url.query = Rack::Utils.build_query(user: raw_info['user_id'])
77
+ url = url.to_s
78
+
79
+ @user_info ||= access_token.get(url).parsed
59
80
  end
60
81
 
61
82
  def team_info
@@ -67,12 +88,24 @@ module OmniAuth
67
88
  access_token.params['incoming_webhook']
68
89
  end
69
90
 
91
+ def bot_info
92
+ return {} unless bot_allowed?
93
+ access_token.params['bot']
94
+ end
95
+
70
96
  def incoming_webhook_allowed?
71
97
  return false unless options['scope']
72
98
  webhooks_scopes = ['incoming-webhook']
73
99
  scopes = options['scope'].split(',')
74
100
  (scopes & webhooks_scopes).any?
75
101
  end
102
+
103
+ def bot_allowed?
104
+ return false unless options['scope']
105
+ bot_scopes = ['bot']
106
+ scopes = options['scope'].split(',')
107
+ (scopes & bot_scopes).any?
108
+ end
76
109
  end
77
110
  end
78
111
  end
@@ -98,3 +98,43 @@ class CredentialsTest < StrategyTestCase
98
98
  refute_has_key "refresh_token", strategy.credentials
99
99
  end
100
100
  end
101
+
102
+ class UserInfoTest < StrategyTestCase
103
+
104
+ def setup
105
+ super
106
+ @access_token = stub("OAuth2::AccessToken")
107
+ strategy.stubs(:access_token).returns(@access_token)
108
+ end
109
+
110
+ test "performs a GET to https://slack.com/api/users.info" do
111
+ strategy.stubs(:raw_info).returns("user_id" => "U123")
112
+ @access_token.expects(:get).with("/api/users.info?user=U123")
113
+ .returns(stub_everything("OAuth2::Response"))
114
+ strategy.user_info
115
+ end
116
+
117
+ test "URI escapes user ID" do
118
+ strategy.stubs(:raw_info).returns("user_id" => "../haxx?U123#abc")
119
+ @access_token.expects(:get).with("/api/users.info?user=..%2Fhaxx%3FU123%23abc")
120
+ .returns(stub_everything("OAuth2::Response"))
121
+ strategy.user_info
122
+ end
123
+ end
124
+
125
+ class SkipInfoTest < StrategyTestCase
126
+
127
+ test 'info should not include extended info when skip_info is specified' do
128
+ @options = { skip_info: true }
129
+ strategy.stubs(:raw_info).returns({})
130
+ assert_equal %w[nickname team user team_id user_id], strategy.info.keys.map(&:to_s)
131
+ end
132
+
133
+ test 'extra should not include extended info when skip_info is specified' do
134
+ @options = { skip_info: true }
135
+ strategy.stubs(:raw_info).returns({})
136
+ strategy.stubs(:webhook_info).returns({})
137
+ assert_equal %w[raw_info web_hook_info bot_info], strategy.extra.keys.map(&:to_s)
138
+ end
139
+
140
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.2.2
122
+ rubygems_version: 2.4.3
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: OmniAuth strategy for Slack