omniauth-gitlab 0.0.1
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.
- data/.gitignore +18 -0
- data/.project +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +7 -0
- data/lib/omniauth-gitlab.rb +9 -0
- data/lib/omniauth-gitlab/version.rb +5 -0
- data/lib/omniauth/strategies/gitlab.rb +61 -0
- data/omniauth-gitlab.gemspec +27 -0
- data/spec/omniauth/strategies/gitlab_spec.rb +83 -0
- data/spec/spec_helper.rb +17 -0
- metadata +172 -0
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>omniauth-gitlab</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
<nature>com.aptana.projects.webnature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ssein
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Omniauth::Gitlab
|
2
|
+
|
3
|
+
This is the strategy for authenticating to your GitLab service. To
|
4
|
+
use it, you'll need to set gitlab url.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'omniauth-gitlab'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install omniauth-gitlab
|
19
|
+
|
20
|
+
## Basic Usage
|
21
|
+
|
22
|
+
use OmniAuth::Builder do
|
23
|
+
provider :gitlab, :site => 'https://your.git.lab.com/'
|
24
|
+
end
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
class GitLab
|
4
|
+
include OmniAuth::Strategy
|
5
|
+
|
6
|
+
option :fields, [:email]
|
7
|
+
option :site, nil
|
8
|
+
option :uid_field, :email
|
9
|
+
option :on_login, nil
|
10
|
+
option :on_registration, nil
|
11
|
+
option :on_failed_registration, nil
|
12
|
+
|
13
|
+
def request_phase
|
14
|
+
if options[:on_login]
|
15
|
+
options[:on_login].call(self.env)
|
16
|
+
else
|
17
|
+
form = OmniAuth::Form.new(:title => (options[:title] || "Gitlab Verification"), :url => callback_path)
|
18
|
+
|
19
|
+
form.text_field 'Email', 'email'
|
20
|
+
form.password_field 'Password', 'password'
|
21
|
+
form.button "Sign In"
|
22
|
+
form.to_response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def callback_phase
|
27
|
+
return fail!(:invalid_credentials) unless identity
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
uid{ identity['id'].to_s }
|
32
|
+
info do
|
33
|
+
{
|
34
|
+
:name => identity['name'],
|
35
|
+
:email => identity['email'],
|
36
|
+
:nickname => identity['username']
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
credentials do
|
41
|
+
{ :token => identity['private_token'] }
|
42
|
+
end
|
43
|
+
|
44
|
+
extra do
|
45
|
+
{ :raw_info => identity }
|
46
|
+
end
|
47
|
+
|
48
|
+
def identity
|
49
|
+
@identity ||= begin
|
50
|
+
conn = Faraday.new(:url => options[:site])
|
51
|
+
resp = conn.post do |req|
|
52
|
+
req.url '/api/v3/session'
|
53
|
+
req.headers['Content-Type'] = 'application/json'
|
54
|
+
req.params = { :email => request['email'], :password => request['password'] }
|
55
|
+
end
|
56
|
+
resp.success? ? MultiJson.load(resp.body) : nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-gitlab/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "omniauth-gitlab"
|
8
|
+
gem.version = Omniauth::Gitlab::VERSION
|
9
|
+
gem.authors = ["ssein"]
|
10
|
+
gem.email = ["ssein@undev.ru"]
|
11
|
+
gem.description = %q{This is the strategy for authenticating to your GitLab service}
|
12
|
+
gem.summary = %q{This is the strategy for authenticating to your GitLab service}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
21
|
+
gem.add_dependency "faraday", "~> 0.8.6"
|
22
|
+
gem.add_dependency 'multi_json', '~> 1.0'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.7'
|
24
|
+
gem.add_development_dependency 'rack-test'
|
25
|
+
gem.add_development_dependency 'simplecov'
|
26
|
+
gem.add_development_dependency 'webmock'
|
27
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::GitLab do
|
4
|
+
attr_accessor :app
|
5
|
+
|
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
|
20
|
+
end
|
21
|
+
|
22
|
+
before(:all) do
|
23
|
+
set_app!
|
24
|
+
end
|
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
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#callback_phase' do
|
34
|
+
|
35
|
+
context 'with valid credentials' 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', :email => '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
|
54
|
+
|
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.name.should eq 'John Smith'
|
61
|
+
auth_hash.info.email.should eq 'john@example.com'
|
62
|
+
auth_hash.info.nickname.should eq 'john_smith'
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with invalid credentials' do
|
68
|
+
before do
|
69
|
+
stub_request(:post, "http://some.site.com/api/v3/session?email=john@test.com&password=incorrect").
|
70
|
+
with(:headers => {'Content-Type'=>'application/json'}).
|
71
|
+
to_return(:status => 401, :body => '{"message":"401Unauthorized"}')
|
72
|
+
post '/auth/gitlab/callback', :email => 'john@test.com', :password => 'incorrect'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should fail with :invalid_credentials' do
|
76
|
+
last_response.should be_redirect
|
77
|
+
last_response.headers['Location'].should eq "/auth/failure?message=invalid_credentials&strategy=gitlab"
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rspec'
|
6
|
+
require 'rack/test'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'omniauth-gitlab'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include WebMock::API
|
13
|
+
config.include Rack::Test::Methods
|
14
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
15
|
+
end
|
16
|
+
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-gitlab
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ssein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.8.6
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.6
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: multi_json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.7'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.7'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rack-test
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: webmock
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: This is the strategy for authenticating to your GitLab service
|
127
|
+
email:
|
128
|
+
- ssein@undev.ru
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- .project
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- lib/omniauth-gitlab.rb
|
141
|
+
- lib/omniauth-gitlab/version.rb
|
142
|
+
- lib/omniauth/strategies/gitlab.rb
|
143
|
+
- omniauth-gitlab.gemspec
|
144
|
+
- spec/omniauth/strategies/gitlab_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
homepage: ''
|
147
|
+
licenses: []
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ! '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.8.24
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: This is the strategy for authenticating to your GitLab service
|
170
|
+
test_files:
|
171
|
+
- spec/omniauth/strategies/gitlab_spec.rb
|
172
|
+
- spec/spec_helper.rb
|