Skip to content

Commit 0fd3d4c

Browse files
author
ssein
committed
init commit
0 parents  commit 0fd3d4c

13 files changed

Lines changed: 306 additions & 0 deletions

File tree

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
.rvmrc
7+
Gemfile.lock
8+
InstalledFiles
9+
_yardoc
10+
coverage
11+
doc/
12+
lib/bundler/man
13+
pkg
14+
rdoc
15+
spec/reports
16+
test/tmp
17+
test/version_tmp
18+
tmp

.project

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--colour

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in omniauth-gitlab.gemspec
4+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "bundler/gem_tasks"
2+
require 'rspec/core/rake_task'
3+
4+
RSpec::Core::RakeTask.new
5+
6+
desc 'Run specs'
7+
task :default => :spec

lib/omniauth-gitlab.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "omniauth-gitlab/version"
2+
require 'faraday'
3+
require 'omniauth/strategies/gitlab'
4+
5+
# module Omniauth
6+
# module Gitlab
7+
# # Your code goes here...
8+
# end
9+
# end

lib/omniauth-gitlab/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Omniauth
2+
module Gitlab
3+
VERSION = "0.0.1"
4+
end
5+
end

lib/omniauth/strategies/gitlab.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
{
42+
:token => identity['private_token']
43+
}
44+
end
45+
46+
extra do
47+
{ :raw_info => identity }
48+
end
49+
50+
def identity
51+
@identity ||= begin
52+
conn = Faraday.new(:url => options[:site])
53+
resp = conn.post do |req|
54+
req.url '/api/v3/session'
55+
req.headers['Content-Type'] = 'application/json'
56+
req.params = { :email => request['email'], :password => request['password'] }
57+
end
58+
resp.success? ? MultiJson.load(resp.body) : nil
59+
end
60+
end
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)