Commit d909c833be7aa2f5aeb0bd69681853b7b3ddce9a
0 parents
Exists in
master
First commit
Showing
11 changed files
with
208 additions
and
0 deletions
Show diff stats
1 | +++ a/LICENSE.txt | |
... | ... | @@ -0,0 +1,22 @@ |
1 | +Copyright (c) 2013 Shahaf Arad | |
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. | ... | ... |
1 | +++ a/README.md | |
... | ... | @@ -0,0 +1,29 @@ |
1 | +# Omniauth::Env | |
2 | + | |
3 | +TODO: Write a gem description | |
4 | + | |
5 | +## Installation | |
6 | + | |
7 | +Add this line to your application's Gemfile: | |
8 | + | |
9 | + gem 'omniauth-env' | |
10 | + | |
11 | +And then execute: | |
12 | + | |
13 | + $ bundle | |
14 | + | |
15 | +Or install it yourself as: | |
16 | + | |
17 | + $ gem install omniauth-env | |
18 | + | |
19 | +## Usage | |
20 | + | |
21 | +TODO: Write usage instructions here | |
22 | + | |
23 | +## Contributing | |
24 | + | |
25 | +1. Fork it | |
26 | +2. Create your feature branch (`git checkout -b my-new-feature`) | |
27 | +3. Commit your changes (`git commit -am 'Add some feature'`) | |
28 | +4. Push to the branch (`git push origin my-new-feature`) | |
29 | +5. Create new Pull Request | ... | ... |
1 | +++ a/lib/omniauth/strategies/env.rb | |
... | ... | @@ -0,0 +1,42 @@ |
1 | +# Based on code from the oa-env gem | |
2 | + | |
3 | +require 'omniauth' | |
4 | +require 'omniauth-ldap/adaptor' | |
5 | + | |
6 | +module OmniAuth | |
7 | + module Strategies | |
8 | + class Env | |
9 | + include OmniAuth::Strategy | |
10 | + | |
11 | + def request_phase | |
12 | + @user_data = {} | |
13 | + @uid = env['HTTP_REMOTE_USER'] | |
14 | + return fail![:no_user] unless @uid | |
15 | + | |
16 | + fill_ldap_info unless @options.empty? | |
17 | + | |
18 | + @env['omniauth.auth'] = auth_hash | |
19 | + @env['REQUEST_METHOD'] = 'GET' | |
20 | + @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback" | |
21 | + | |
22 | + call_app! | |
23 | + end | |
24 | + | |
25 | + uid { @uid } | |
26 | + | |
27 | + info { @user_data } | |
28 | + | |
29 | + private | |
30 | + | |
31 | + def fill_ldap_info | |
32 | + adaptor = OmniAuth::LDAP::Adaptor.new @options | |
33 | + | |
34 | + filter = Net::LDAP::Filter.eq('cn', @uid) | |
35 | + adaptor.connection.search(base: @options[:base], filter: filter) do |entry| | |
36 | + @user_data[:name] = "#{entry.givenname.first} #{entry.sn.first}" | |
37 | + @user_data[:email] = entry.mail.first | |
38 | + end | |
39 | + end | |
40 | + end | |
41 | + end | |
42 | +end | ... | ... |
1 | +++ a/lib/omniauth/strategies/env.rb~ | |
... | ... | @@ -0,0 +1,40 @@ |
1 | +require 'omniauth' | |
2 | +require 'omniauth-ldap/adaptor' | |
3 | + | |
4 | +module OmniAuth | |
5 | + module Strategies | |
6 | + class Env | |
7 | + include OmniAuth::Strategy | |
8 | + | |
9 | + def request_phase | |
10 | + @user_data = {} | |
11 | + @uid = env['HTTP_REMOTE_USER'] | |
12 | + return fail![:no_user] unless @uid | |
13 | + | |
14 | + fill_ldap_info unless @options.empty? | |
15 | + | |
16 | + @env['omniauth.auth'] = auth_hash | |
17 | + @env['REQUEST_METHOD'] = 'GET' | |
18 | + @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback" | |
19 | + | |
20 | + call_app! | |
21 | + end | |
22 | + | |
23 | + uid { @uid } | |
24 | + | |
25 | + info { @user_data } | |
26 | + | |
27 | + private | |
28 | + | |
29 | + def fill_ldap_info | |
30 | + adaptor = OmniAuth::LDAP::Adaptor.new @options | |
31 | + | |
32 | + filter = Net::LDAP::Filter.eq('cn', @uid) | |
33 | + adaptor.connection.search(base: @options[:base], filter: filter) do |entry| | |
34 | + @user_data[:name] = "#{entry.givenname.first} #{entry.sn.first}" | |
35 | + @user_data[:email] = entry.mail.first | |
36 | + end | |
37 | + end | |
38 | + end | |
39 | + end | |
40 | +end | ... | ... |
1 | +++ a/omniauth-env.gemspec | |
... | ... | @@ -0,0 +1,23 @@ |
1 | +# coding: utf-8 | |
2 | +require File.expand_path('../lib/omniauth-env/version', __FILE__) | |
3 | + | |
4 | +Gem::Specification.new do |spec| | |
5 | + spec.name = "omniauth-env" | |
6 | + spec.version = OmniAuth::Env::VERSION | |
7 | + spec.authors = ["Shahaf Arad"] | |
8 | + spec.email = ["shahaf2a@gmail.com"] | |
9 | + spec.description = %q{REMOTE_USER strategy for omniauth.} | |
10 | + spec.summary = %q{REMOTE_USER strategy for omniauth.} | |
11 | + spec.homepage = "https://github.com/av3r4ge/omniauth-env" | |
12 | + | |
13 | + spec.files = `git ls-files`.split($/) | |
14 | + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | |
15 | + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | |
16 | + spec.require_paths = ["lib"] | |
17 | + | |
18 | + spec.add_runtime_dependency 'omniauth', '~> 1.0' | |
19 | + spec.add_runtime_dependency 'gitlab_omniauth-ldap', '~> 1.0.3' | |
20 | + | |
21 | + spec.add_development_dependency "bundler", "~> 1.3" | |
22 | + spec.add_development_dependency "rake" | |
23 | +end | ... | ... |
1 | +++ a/omniauth-env.gemspec~ | |
... | ... | @@ -0,0 +1,23 @@ |
1 | +# coding: utf-8 | |
2 | +require File.expand_path('../lib/omniauth-env/version', __FILE__) | |
3 | + | |
4 | +Gem::Specification.new do |spec| | |
5 | + spec.name = "omniauth-env" | |
6 | + spec.version = Omniauth::Env::VERSION | |
7 | + spec.authors = ["Shahaf Arad"] | |
8 | + spec.email = ["shahaf2a@gmail.com"] | |
9 | + spec.description = %q{REMOTE_USER strategy for omniauth.} | |
10 | + spec.summary = %q{REMOTE_USER strategy for omniauth.} | |
11 | + spec.homepage = "https://github.com/av3r4ge/omniauth-env" | |
12 | + | |
13 | + spec.files = `git ls-files`.split($/) | |
14 | + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | |
15 | + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | |
16 | + spec.require_paths = ["lib"] | |
17 | + | |
18 | + spec.add_runtime_dependency 'omniauth', '~> 1.0' | |
19 | + spec.add_runtime_dependency 'gitlab_omniauth-ldap', '~> 1.0.3' | |
20 | + | |
21 | + spec.add_development_dependency "bundler", "~> 1.3" | |
22 | + spec.add_development_dependency "rake" | |
23 | +end | ... | ... |