omniauth-github-organization 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: f622b7bb7d431b7b0cc18aa1f8542cee4c0316c7864b2d8bad55c3c46ea12996
4
- data.tar.gz: 1599886d8c96e9a9d303be6fec714e63a7bb21272f0f03f736cdca64c00a9aaf
3
+ metadata.gz: 0de1670bdccb65312021de8fa605c7b1f916927d461e254bedcf78e6705809c7
4
+ data.tar.gz: 52d3f97602da9b052a931efbf83ce0bdf61b78fd6e3ae0f86274ea6503693c44
5
5
  SHA512:
6
- metadata.gz: 87e4307ee5ee1e6daac28f6d08bd2f3b4697ed8fb72ffb89728d411eb427d53563314ab0037af11972ad46962e23514d0c2573c8785a71fdbe18e431b94a205d
7
- data.tar.gz: 05d1fc1239e1b2307bfede0a1368a03b97a834c3c14631ef08e7fabd643d18b8cf7943041469ea11a301c3f8701c7a0338f086c6c5846620fdd64e6f3d7e6db9
6
+ metadata.gz: 14bc8f4374cf6646f01de5c0aabbc57591ad727c9cc0b8c6a0428ba565a4518ee16889f2e21e7503f48786a588290c0659f8216cc0bfab1f5a2084aa649968ca
7
+ data.tar.gz: 131fae3accfb3fe29ef2fb1eed03aa51f605e0787b900301f9fb37477345b26c260a5eb505594c7dfd6a1d13a6f8cfbf5398ed993aa9f647d635cdb54615454b
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GitHubOrganization
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
5
5
  end
@@ -28,14 +28,25 @@ module OmniAuth
28
28
  end
29
29
 
30
30
  def callback_phase
31
- super
32
- return fail!(:user_denied, CallbackError.new(:user_denied, options['organization'])) unless organizations.include? options['organization']
33
- end
34
-
35
- def organizations
36
- access_token.options[:mode] = :query
37
- organizations = access_token.get('user/orgs', headers: { 'Accept' => 'application/vnd.github.v3' }).parsed
38
- organizations.map { |x| x['login'] }
31
+ error = request.params["error_reason"] || request.params["error"]
32
+ if error
33
+ fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
34
+ elsif !options.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state"))
35
+ fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected"))
36
+ else
37
+ self.access_token = build_access_token
38
+ self.access_token = access_token.refresh! if access_token.expired?
39
+ self.access_token.options[:mode] = :query
40
+ organizations = self.access_token.get('user/orgs', headers: { 'Accept' => 'application/vnd.github.v3' }).parsed
41
+ fail!(:user_denied, CallbackError.new(:user_denied, options['organization'])) unless organizations.map { |x| x['login'] }.include? options['organization']
42
+ super
43
+ end
44
+ rescue ::OAuth2::Error, CallbackError => e
45
+ fail!(:invalid_credentials, e)
46
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
47
+ fail!(:timeout, e)
48
+ rescue ::SocketError => e
49
+ fail!(:failed_to_connect, e)
39
50
  end
40
51
 
41
52
  uid { raw_info['id'].to_s }
@@ -46,7 +57,6 @@ module OmniAuth
46
57
  'email' => email,
47
58
  'name' => raw_info['name'],
48
59
  'image' => raw_info['avatar_url'],
49
- 'organizations' => organizations,
50
60
  'urls' => {
51
61
  'GitHub' => raw_info['html_url'],
52
62
  'Blog' => raw_info['blog'],
@@ -26,10 +26,15 @@ describe OmniAuth::Strategies::GitHubOrganization do
26
26
  end
27
27
 
28
28
  before(:each) do
29
+ OmniAuth.config.test_mode = true
29
30
  allow(subject).to receive(:access_token).and_return(access_token)
30
31
  allow(subject).to receive(:organizations).and_return(%w[example test])
31
32
  end
32
33
 
34
+ after do
35
+ OmniAuth.config.test_mode = false
36
+ end
37
+
33
38
  context 'client options' do
34
39
  it 'should have correct site' do
35
40
  expect(subject.options.client_options.site).to eq('https://api.github.com')
@@ -169,10 +174,4 @@ describe OmniAuth::Strategies::GitHubOrganization do
169
174
  end
170
175
  end
171
176
 
172
- it 'is should return error if organization not match' do
173
- allow(subject).to receive(:organizations).and_return(%w[not_match])
174
- expect(subject).to receive(:fail!).with(:user_denied, anything)
175
- subject.callback_phase
176
- end
177
-
178
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-github-organization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Ding