omniauth-gitlab 0.0.5 → 0.0.6

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: 167ea9851f6d073cf7f20a5b52bc49012cb9974f
4
- data.tar.gz: 63901981942a3047eed7c2d5097abb61f5c33a8a
3
+ metadata.gz: a198a18e23071e86551c6da0347caadaf5e02f88
4
+ data.tar.gz: fd1443f67e8224c237f3d947283b5a9286731f70
5
5
  SHA512:
6
- metadata.gz: 1984ae2b2b9d636bebdf04013bba916578263dcab2499054d035e81f1ce94468cacc57fee9d849607d75482b3588301f2150c40dba15f091fc5e20b018b60855
7
- data.tar.gz: 2c3ec21dd67e92e3a49057daa6fc9445fc37692b2f702875e38008f78a9ba7a9c23ab5bbc6aa3e7be47c89c7a55c41b83970bbbc2b591fd6e11d9d8664eec9ac
6
+ metadata.gz: 8f62fab0475285f7daa0e4c6ea1f23bcc0979dd88292d1b7e2a0fa8930542f162fb31b0a3392577887a41ae959eafd3da7d64583747ef1cd27c4d4a84a930996
7
+ data.tar.gz: af2a55b71ae642e9629d61a0db2e2f78aa84758e0cb09ddd7ceaca9022c8261a9871645b0f72870a62b5fff9c80c60f92ea15f153ac245a4ab5fbd8054fd0dc1
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Gitlab
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'multi_json'
3
+ require 'omniauth'
3
4
 
4
5
  module OmniAuth
5
6
  module Strategies
@@ -19,8 +20,8 @@ module OmniAuth
19
20
  options[:on_login].call(self.env)
20
21
  else
21
22
  form = OmniAuth::Form.new(:title => (options[:title] || "Gitlab Verification"), :url => callback_path)
22
-
23
- form.text_field 'Email', 'email'
23
+
24
+ form.text_field 'Username or e-mail', 'login'
24
25
  form.password_field 'Password', 'password'
25
26
  form.button "Sign In"
26
27
  form.to_response
@@ -31,38 +32,47 @@ module OmniAuth
31
32
  return fail!(:invalid_credentials) unless identity
32
33
  super
33
34
  end
34
-
35
+
35
36
  uid{ identity['id'].to_s }
36
37
  info do
37
38
  {
38
39
  :name => identity['name'],
39
40
  :email => identity['email'],
40
41
  :nickname => identity['username']
41
- }
42
+ }
42
43
  end
43
-
44
+
44
45
  credentials do
45
46
  { :token => identity['private_token'] }
46
47
  end
47
-
48
- extra do
48
+
49
+ extra do
49
50
  { :raw_info => identity }
50
51
  end
51
-
52
+
52
53
  def identity
53
54
  @identity ||= begin
54
55
  conn = Faraday.new(:url => options[:site])
56
+ key = is_email?(request['login']) ? :email : :login
55
57
  resp = conn.post do |req|
56
58
  req.url "/api/#{options[:v]}/session"
57
59
  req.headers['Content-Type'] = 'application/json'
58
- req.params = { :email => request['email'], :password => request['password'] }
60
+ req.params = {
61
+ key => request['login'],
62
+ :password => request['password']
63
+ }
59
64
  end
60
65
  resp.success? ? MultiJson.decode(resp.body) : nil
61
- end
66
+ end
67
+ end
68
+
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}/)
62
72
  end
63
73
  end
64
74
  end
65
75
  end
66
76
 
67
77
 
68
- OmniAuth.config.add_camelization 'gitlab', 'GitLab'
78
+ OmniAuth.config.add_camelization 'gitlab', 'GitLab'
@@ -18,7 +18,7 @@ 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.7.6"
21
+ gem.add_dependency "faraday", "~> 0.9.0"
22
22
  gem.add_dependency 'multi_json', '~> 1.0'
23
23
  gem.add_development_dependency 'rspec', '~> 2.7'
24
24
  gem.add_development_dependency 'rack-test'
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe OmniAuth::Strategies::GitLab do
4
4
  attr_accessor :app
5
-
5
+
6
6
  let(:auth_hash){ last_response.headers['env']['omniauth.auth'] }
7
-
7
+
8
8
  def set_app!(gitlab_options = {})
9
9
  old_app = self.app
10
10
  self.app = Rack::Builder.app do
@@ -31,8 +31,8 @@ describe OmniAuth::Strategies::GitLab do
31
31
  end
32
32
 
33
33
  describe '#callback_phase' do
34
-
35
- context 'with valid credentials' do
34
+
35
+ context 'with valid credentials using email' do
36
36
  before do
37
37
  stub_request(:post, "http://some.site.com/api/v3/session?email=john@test.com&password=awesome").
38
38
  with(:headers => {'Content-Type'=>'application/json'}).
@@ -45,9 +45,9 @@ describe OmniAuth::Strategies::GitLab do
45
45
  "created_at": "2012-05-23T08:00:58Z",
46
46
  "blocked": true
47
47
  }')
48
- post '/auth/gitlab/callback', :email => 'john@test.com', :password => 'awesome'
48
+ post '/auth/gitlab/callback', :login => 'john@test.com', :password => 'awesome'
49
49
  end
50
-
50
+
51
51
  it 'should populate the auth hash' do
52
52
  auth_hash.should be_kind_of(Hash)
53
53
  end
@@ -57,27 +57,57 @@ describe OmniAuth::Strategies::GitLab do
57
57
  end
58
58
 
59
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'
60
62
  auth_hash.info.name.should eq 'John Smith'
63
+ end
64
+ end
65
+
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
85
+
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
61
91
  auth_hash.info.email.should eq 'john@example.com'
62
- auth_hash.info.nickname.should eq 'john_smith'
92
+ auth_hash.info.nickname.should eq 'john_smith'
93
+ auth_hash.info.name.should eq 'John Smith'
63
94
  end
64
-
65
95
  end
66
-
96
+
67
97
  context 'with invalid credentials' do
68
98
  before do
69
99
  stub_request(:post, "http://some.site.com/api/v3/session?email=john@test.com&password=incorrect").
70
100
  with(:headers => {'Content-Type'=>'application/json'}).
71
101
  to_return(:status => 401, :body => '{"message":"401Unauthorized"}')
72
- post '/auth/gitlab/callback', :email => 'john@test.com', :password => 'incorrect'
102
+ post '/auth/gitlab/callback', :login => 'john@test.com', :password => 'incorrect'
73
103
  end
74
104
 
75
105
  it 'should fail with :invalid_credentials' do
76
106
  last_response.should be_redirect
77
107
  last_response.headers['Location'].should eq "/auth/failure?message=invalid_credentials&strategy=gitlab"
78
- end
108
+ end
79
109
 
80
110
  end
81
111
  end
82
-
83
- end
112
+
113
+ end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ssein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-18 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.7.6
33
+ version: 0.9.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.7.6
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: multi_json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.7'
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
68
  version: '2.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: This is the strategy for authenticating to your GitLab service
@@ -115,9 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - .gitignore
119
- - .project
120
- - .rspec
118
+ - ".gitignore"
119
+ - ".project"
120
+ - ".rspec"
121
121
  - Gemfile
122
122
  - LICENSE.txt
123
123
  - README.md
@@ -137,20 +137,21 @@ require_paths:
137
137
  - lib
138
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - '>='
140
+ - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.0.14
150
+ rubygems_version: 2.2.2
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: This is the strategy for authenticating to your GitLab service
154
154
  test_files:
155
155
  - spec/omniauth/strategies/gitlab_spec.rb
156
156
  - spec/spec_helper.rb
157
+ has_rdoc: