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 +4 -4
- data/README.md +16 -4
- data/lib/omniauth/strategies/gitlab.rb +15 -57
- data/lib/omniauth-gitlab/version.rb +1 -1
- data/omniauth-gitlab.gemspec +3 -3
- data/spec/omniauth/strategies/gitlab_spec.rb +36 -95
- data/spec/spec_helper.rb +1 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d93eb381f07c12f9df411be7caf637e000cb806
|
4
|
+
data.tar.gz: 630aa5b0f829f7dee788c4cdb7539d0b5055ec70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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,
|
26
|
+
provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET']
|
24
27
|
end
|
25
28
|
|
26
|
-
|
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
|
-
|
2
|
-
require '
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
option :client_options, {
|
9
|
+
site: 'https://gitlab.com',
|
10
|
+
authorize_url: '/oauth/authorize',
|
11
|
+
token_url: '/oauth/token'
|
12
|
+
}
|
23
13
|
|
24
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
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
|
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
|
-
|
70
|
-
|
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
|
data/omniauth-gitlab.gemspec
CHANGED
@@ -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
|
22
|
-
gem.
|
23
|
-
gem.add_development_dependency 'rspec', '~>
|
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(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
23
|
-
set_app!
|
24
|
-
end
|
24
|
+
subject { gitlab_service }
|
25
25
|
|
26
|
-
|
27
|
-
|
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 '
|
34
|
-
|
35
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
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
|
67
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
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
|
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:
|
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:
|
28
|
+
name: omniauth-oauth2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
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:
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
48
|
-
type: :
|
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
|
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: '
|
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: '
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|