omniauth-gitlab 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a198a18e23071e86551c6da0347caadaf5e02f88
4
- data.tar.gz: fd1443f67e8224c237f3d947283b5a9286731f70
3
+ metadata.gz: 0d93eb381f07c12f9df411be7caf637e000cb806
4
+ data.tar.gz: 630aa5b0f829f7dee788c4cdb7539d0b5055ec70
5
5
  SHA512:
6
- metadata.gz: 8f62fab0475285f7daa0e4c6ea1f23bcc0979dd88292d1b7e2a0fa8930542f162fb31b0a3392577887a41ae959eafd3da7d64583747ef1cd27c4d4a84a930996
7
- data.tar.gz: af2a55b71ae642e9629d61a0db2e2f78aa84758e0cb09ddd7ceaca9022c8261a9871645b0f72870a62b5fff9c80c60f92ea15f153ac245a4ab5fbd8054fd0dc1
6
+ metadata.gz: 36e720d845afad73f409de4014dd9ef5ed88288c850fc92411fc169042e63823d8182e75c90546accc1a559c477f76e1da064e789274dde9e245a03213ab3f94
7
+ data.tar.gz: 64568a2529f5631d33309e7b740498906015382809f348a1a1830609165a6de3451e5adfd54758050a7dcc58af13ea37179717c12b6a29ad679e66f6d04701e2
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Omniauth::Gitlab
2
2
 
3
- This is the strategy for authenticating to your GitLab service. To
4
- use it, you'll need to set gitlab url.
3
+ This is the OAuth2 strategy for authenticating to your GitLab service.
5
4
 
5
+ ## Requirements
6
+
7
+ Gitlab 7.7.0+
8
+
6
9
  ## Installation
7
10
 
8
11
  Add this line to your application's Gemfile:
@@ -20,10 +23,19 @@ Or install it yourself as:
20
23
  ## Basic Usage
21
24
 
22
25
  use OmniAuth::Builder do
23
- provider :gitlab, :site => 'https://your.git.lab.com/', :v => 'v3'
26
+ provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET']
24
27
  end
25
28
 
26
- Default value for :v parameter is 'v3'.
29
+ ## Standalone Usage
30
+
31
+ use OmniAuth::Builder do
32
+ provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET'],
33
+ client_options: {
34
+ site: 'https://gitlab.YOURDOMAIN.com',
35
+ authorize_url: '/oauth/authorize',
36
+ token_url: '/oauth/token'
37
+ }
38
+ end
27
39
 
28
40
  ## Contributing
29
41
 
@@ -1,74 +1,32 @@
1
- require 'faraday'
2
- require 'multi_json'
3
- require 'omniauth'
1
+
2
+ require 'omniauth-oauth2'
4
3
 
5
4
  module OmniAuth
6
5
  module Strategies
7
- class GitLab
8
- include OmniAuth::Strategy
9
-
10
- option :fields, [:email]
11
- option :site, nil
12
- option :v, 'v3'
13
- option :uid_field, :email
14
- option :on_login, nil
15
- option :on_registration, nil
16
- option :on_failed_registration, nil
6
+ class GitLab < OmniAuth::Strategies::OAuth2
17
7
 
18
- def request_phase
19
- if options[:on_login]
20
- options[:on_login].call(self.env)
21
- else
22
- form = OmniAuth::Form.new(:title => (options[:title] || "Gitlab Verification"), :url => callback_path)
8
+ option :client_options, {
9
+ site: 'https://gitlab.com',
10
+ authorize_url: '/oauth/authorize',
11
+ token_url: '/oauth/token'
12
+ }
23
13
 
24
- form.text_field 'Username or e-mail', 'login'
25
- form.password_field 'Password', 'password'
26
- form.button "Sign In"
27
- form.to_response
28
- end
29
- end
30
-
31
- def callback_phase
32
- return fail!(:invalid_credentials) unless identity
33
- super
34
- end
14
+ uid { raw_info['id'].to_s }
35
15
 
36
- uid{ identity['id'].to_s }
37
16
  info do
38
17
  {
39
- :name => identity['name'],
40
- :email => identity['email'],
41
- :nickname => identity['username']
18
+ name: raw_info['name'],
19
+ username: raw_info['username'],
20
+ email: raw_info['email']
42
21
  }
43
22
  end
44
23
 
45
- credentials do
46
- { :token => identity['private_token'] }
47
- end
48
-
49
24
  extra do
50
- { :raw_info => identity }
51
- end
52
-
53
- def identity
54
- @identity ||= begin
55
- conn = Faraday.new(:url => options[:site])
56
- key = is_email?(request['login']) ? :email : :login
57
- resp = conn.post do |req|
58
- req.url "/api/#{options[:v]}/session"
59
- req.headers['Content-Type'] = 'application/json'
60
- req.params = {
61
- key => request['login'],
62
- :password => request['password']
63
- }
64
- end
65
- resp.success? ? MultiJson.decode(resp.body) : nil
66
- end
25
+ { raw_info: raw_info }
67
26
  end
68
27
 
69
- # check if login string looks like email
70
- def is_email?(str)
71
- str.match(/[a-zA-Z0-9._%]@(?:[a-zA-Z0-9]+\.)[a-zA-Z]{2,4}/)
28
+ def raw_info
29
+ @raw_info ||= access_token.get('/api/v3/user').parsed
72
30
  end
73
31
  end
74
32
  end
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Gitlab
3
- VERSION = "0.0.6"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency 'omniauth', '~> 1.0'
21
- gem.add_dependency "faraday", "~> 0.9.0"
22
- gem.add_dependency 'multi_json', '~> 1.0'
23
- gem.add_development_dependency 'rspec', '~> 2.7'
21
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
22
+ gem.add_development_dependency 'rspec', '~> 3.1'
23
+ gem.add_development_dependency 'rspec-its', '~> 1.0'
24
24
  gem.add_development_dependency 'rack-test'
25
25
  gem.add_development_dependency 'simplecov'
26
26
  gem.add_development_dependency 'webmock'
@@ -1,113 +1,54 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OmniAuth::Strategies::GitLab do
4
- attr_accessor :app
5
4
 
6
- let(:auth_hash){ last_response.headers['env']['omniauth.auth'] }
7
-
8
- def set_app!(gitlab_options = {})
9
- old_app = self.app
10
- self.app = Rack::Builder.app do
11
- use Rack::Session::Cookie
12
- use OmniAuth::Strategies::GitLab, {:site => 'http://some.site.com/' }.merge(gitlab_options)
13
- run lambda{|env| [404, {'env' => env}, ["HELLO!"]]}
14
- end
15
- if block_given?
16
- yield
17
- self.app = old_app
18
- end
19
- self.app
5
+ let(:access_token) { double('AccessToken') }
6
+ let(:parsed_response) { double('ParsedResponse') }
7
+ let(:response) { double('Response', parsed: parsed_response) }
8
+
9
+ let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
10
+ let(:enterprise_authorize_url) { '/oauth/authorize' }
11
+ let(:enterprise_token_url) { '/oauth/access_token' }
12
+
13
+ let(:gitlab_service) { OmniAuth::Strategies::GitLab.new({}) }
14
+ let(:enterprise) do
15
+ OmniAuth::Strategies::GitLab.new('GITLAB_KEY', 'GITLAB_SECRET',
16
+ client_options: {
17
+ site: enterprise_site,
18
+ authorize_url: enterprise_authorize_url,
19
+ token_url: enterprise_token_url
20
+ }
21
+ )
20
22
  end
21
23
 
22
- before(:all) do
23
- set_app!
24
- end
24
+ subject { gitlab_service }
25
25
 
26
- describe '#request_phase' do
27
- it 'should display a form' do
28
- get '/auth/gitlab'
29
- last_response.body.should be_include("<form")
30
- end
26
+ before(:each) do
27
+ allow(subject).to receive(:access_token).and_return(access_token)
31
28
  end
32
29
 
33
- describe '#callback_phase' do
34
-
35
- context 'with valid credentials using email' do
36
- before do
37
- stub_request(:post, "http://some.site.com/api/v3/session?email=john@test.com&password=awesome").
38
- with(:headers => {'Content-Type'=>'application/json'}).
39
- to_return(:status => 200, :body => '{
40
- "id": 1,
41
- "username": "john_smith",
42
- "email": "john@example.com",
43
- "name": "John Smith",
44
- "private_token": "dd34asd13as",
45
- "created_at": "2012-05-23T08:00:58Z",
46
- "blocked": true
47
- }')
48
- post '/auth/gitlab/callback', :login => 'john@test.com', :password => 'awesome'
49
- end
50
-
51
- it 'should populate the auth hash' do
52
- auth_hash.should be_kind_of(Hash)
53
- end
30
+ describe 'client options' do
31
+ context 'with defaults' do
32
+ subject { gitlab_service.options.client_options }
54
33
 
55
- it 'should populate the uid' do
56
- auth_hash['uid'].should eq '1'
57
- end
58
-
59
- it 'should populate the info hash' do
60
- auth_hash.info.email.should eq 'john@example.com'
61
- auth_hash.info.nickname.should eq 'john_smith'
62
- auth_hash.info.name.should eq 'John Smith'
63
- end
34
+ its(:site) { is_expected.to eq 'https://gitlab.com' }
35
+ its(:authorize_url) { is_expected.to eq '/oauth/authorize' }
36
+ its(:token_url) { is_expected.to eq '/oauth/token' }
64
37
  end
65
38
 
66
- context 'with valid credentials using login' do
67
- before do
68
- stub_request(:post, "http://some.site.com/api/v3/session?login=john_smith&password=awesome").
69
- with(:headers => {'Content-Type'=>'application/json'}).
70
- to_return(:status => 200, :body => '{
71
- "id": 1,
72
- "username": "john_smith",
73
- "email": "john@example.com",
74
- "name": "John Smith",
75
- "private_token": "dd34asd13as",
76
- "created_at": "2012-05-23T08:00:58Z",
77
- "blocked": true
78
- }')
79
- post '/auth/gitlab/callback', :login => 'john_smith', :password => 'awesome'
80
- end
81
-
82
- it 'should populate the auth hash' do
83
- auth_hash.should be_kind_of(Hash)
84
- end
39
+ context 'with override' do
40
+ subject { enterprise.options.client_options }
85
41
 
86
- it 'should populate the uid' do
87
- auth_hash['uid'].should eq '1'
88
- end
89
-
90
- it 'should populate the info hash' do
91
- auth_hash.info.email.should eq 'john@example.com'
92
- auth_hash.info.nickname.should eq 'john_smith'
93
- auth_hash.info.name.should eq 'John Smith'
94
- end
42
+ its(:site) { is_expected.to eq enterprise_site }
43
+ its(:authorize_url) { is_expected.to eq enterprise_authorize_url }
44
+ its(:token_url) { is_expected.to eq enterprise_token_url }
95
45
  end
46
+ end
96
47
 
97
- context 'with invalid credentials' do
98
- before do
99
- stub_request(:post, "http://some.site.com/api/v3/session?email=john@test.com&password=incorrect").
100
- with(:headers => {'Content-Type'=>'application/json'}).
101
- to_return(:status => 401, :body => '{"message":"401Unauthorized"}')
102
- post '/auth/gitlab/callback', :login => 'john@test.com', :password => 'incorrect'
103
- end
104
-
105
- it 'should fail with :invalid_credentials' do
106
- last_response.should be_redirect
107
- last_response.headers['Location'].should eq "/auth/failure?message=invalid_credentials&strategy=gitlab"
108
- end
109
-
48
+ describe '#raw_info' do
49
+ it 'sent request to current user endpoint' do
50
+ expect(access_token).to receive(:get).with('/api/v3/user').and_return(response)
51
+ expect(subject.raw_info).to eq(parsed_response)
110
52
  end
111
53
  end
112
-
113
54
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ $:.unshift File.expand_path('../../lib', __FILE__)
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
  require 'rspec'
6
+ require 'rspec/its'
6
7
  require 'rack/test'
7
8
  require 'webmock/rspec'
8
9
  require 'omniauth'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ssein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -25,47 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
28
+ name: omniauth-oauth2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.0
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: multi_json
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :runtime
47
+ version: '3.1'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.7'
61
+ version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.7'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement