omniauth-remote-user-0.1.3/0000755000004100000410000000000012670342462015642 5ustar www-datawww-dataomniauth-remote-user-0.1.3/Rakefile0000644000004100000410000000014312670342462017305 0ustar www-datawww-datarequire 'bundler' Bundler::GemHelper.install_tasks task :default => :spec task :test => :spec omniauth-remote-user-0.1.3/Gemfile0000644000004100000410000000037612670342462017143 0ustar www-datawww-datasource "http://rubygems.org" gemspec group :development do gem 'guard' gem 'guard-bundler' gem 'guard-rspec' gem 'rake' gem 'bundler' gem 'sinatra' end group :test do gem 'coveralls' gem 'rack-test' gem 'simplecov' gem 'rspec' end omniauth-remote-user-0.1.3/omniauth-remote-user.gemspec0000644000004100000410000000200412670342462023274 0ustar www-datawww-datarequire File.dirname(__FILE__) + '/lib/omniauth-remote-user/version' Gem::Specification.new do |gem| gem.add_runtime_dependency 'omniauth', '~> 1.0' gem.name = 'omniauth-remote-user' gem.version = Omniauth::RemoteUser::VERSION gem.description = 'Authentication with Remote-User HTTP header for Omniauth.' gem.summary = 'Authentication with HTTP Remote User' gem.email = ['kanashiro.duarte@gmail.com', 'thiagitosouza@gmail.com', 'rodrigosiqueiramelo@gmail.com','macartur.sc@gmail.com','terceiro@softwarelivre.org'] gem.homepage = 'http://beta.softwarepublico.gov.br/gitlab/softwarepublico/omniauth-remote-user' gem.authors = ['Lucas Kanashiro', 'Thiago Ribeiro', 'Rodrigo Siqueira','Macartur Sousa', 'Antonio Terceiro'] gem.require_paths = %w(lib) gem.files = %w{Rakefile LICENSE.md README.md config.ru Gemfile} + Dir.glob("*.gemspec") + Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } gem.license = "Expat" gem.required_rubygems_version = '>= 1.3.5' end omniauth-remote-user-0.1.3/spec/0000755000004100000410000000000012670342462016574 5ustar www-datawww-dataomniauth-remote-user-0.1.3/spec/omniauth/0000755000004100000410000000000012670342462020420 5ustar www-datawww-dataomniauth-remote-user-0.1.3/spec/omniauth/strategies/0000755000004100000410000000000012670342462022572 5ustar www-datawww-dataomniauth-remote-user-0.1.3/spec/omniauth/strategies/remote_user_spec.rb0000644000004100000410000000741312670342462026467 0ustar www-datawww-datarequire 'spec_helper' describe 'Test Strategy Remote_User' do let(:app) do Rack::Builder.new do |b| b.use Rack::Session::Cookie, :secret => 'abc123' b.use OmniAuth::Strategies::RemoteUser b.run lambda { |_env| [200, {}, ['My body']] } end.to_app end context 'Without HTTP_REMOTE_USER and not logged in' do before(:each){ get '/', {}, {} } it 'Do nothing' do expect(last_response.status).to eq(200) expect(last_request.cookies['_remote_user']).to eq(nil) end end context 'Without HTTP_REMOTE_USER and logged in' do before(:each){ clear_cookies set_cookie "_remote_user=test" get '/', {}, {} } it 'Logout curreent user' do expect(last_request.cookies['_remote_user']).to eq('test') expect(last_response.status).to eq(302) expect(last_response['Set-Cookie']).to include("_remote_user=") expect(last_response['Set-Cookie']).to include("path=") end end context 'With HTTP_REMOTE_USER and not logged in' do before(:each){ get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } } it 'logs HTTP_REMOTE_USER in' do expect(last_response.status).to eq(302) expect(last_response['Set-Cookie']).to include('_remote_user=foobar') expect(last_response['Set-Cookie']).to include('path=') end end context 'With HTTP_REMOTE_USER, logged in and current user equals HTTP_REMOTE_USER' do before(:each){ clear_cookies set_cookie "_remote_user=foobar" get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } } it 'Do nothing' do expect(last_request.cookies['_remote_user']).to eq('foobar') expect(last_response.status).to eq(200) expect(last_response['Set-Cookie']).to eq(nil) end end context 'With HTTP_REMOTE_USER, logged in and current user not equals HTTP_REMOTE_USER' do before(:each){ clear_cookies set_cookie "_remote_user=foobar" get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar2' } } it 'Logout current user and login HTTP_REMOTE_USER' do expect(last_request.cookies['_remote_user']).to eq('foobar') expect(last_response.status).to eq(302) end end context 'Verify omniauth hash with HTTP_REMOTE_USER_DATA' do before(:each){ clear_cookies set_cookie "_remote_user=foobar" post '/auth/RemoteUser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar', 'HTTP_REMOTE_USER_DATA' => JSON.dump({'name' => 'foobar barfoo', 'email' => 'foobar@test.com'})} } it 'Verify uid' do expect(last_request.env['omniauth.auth']['uid']).to eq('foobar') end it 'Verify info' do expect(last_request.env['omniauth.auth']['info']['nickname']).to eq('foobar') expect(last_request.env['omniauth.auth']['info']['email']).to eq('foobar@test.com') expect(last_request.env['omniauth.auth']['info']['lastname']).to eq('barfoo') expect(last_request.env['omniauth.auth']['info']['firstname']).to eq('foobar') end end context 'Verify omniauth.auth info without HTTP_REMOTE_USER_DATA' do before(:each){ clear_cookies set_cookie "_remote_user=foobar" post '/auth/RemoteUser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar' } } it 'Verify uid' do expect(last_request.env['omniauth.auth']['uid']).to eq('foobar') end it 'Verify info' do expect(last_request.env['omniauth.auth']['info']).to eq({}) end end context 'With HTTP_REMOTE_USER and ' do before(:each){ set_cookie "_remote_user=foobar" get "auth/RemoteUser", {}, { 'HTTP_REMOTE_USER' => 'foobar' } } it 'redirect for callback' do expect(last_response.status).to eq(302) expect(last_response.location).to eq("/auth/RemoteUser/callback") end end end omniauth-remote-user-0.1.3/spec/spec_helper.rb0000644000004100000410000000113412670342462021411 0ustar www-datawww-dataif RUBY_VERSION >= '1.9' require 'simplecov' require 'coveralls' SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter] SimpleCov.start do add_filter '/spec' #minimum_coverage(90) end end require 'rubygems' require 'bundler' require 'rack/test' require 'rspec' require 'rack/test' require 'omniauth' require 'omniauth/test' Bundler.setup :default, :development, :test require 'rack/test' require 'omniauth/remote-user' RSpec.configure do |config| config.include Rack::Test::Methods config.extend OmniAuth::Test::StrategyMacros, :type => :strategy end omniauth-remote-user-0.1.3/LICENSE.md0000644000004100000410000000217212670342462017250 0ustar www-datawww-dataCopyright © Lucas Kanashiro, Thiago Ribeiro, Rodrigo Siqueira, Macartur Sousa, Antonio Terceiro Expat (aka MIT) License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. omniauth-remote-user-0.1.3/lib/0000755000004100000410000000000012670342462016410 5ustar www-datawww-dataomniauth-remote-user-0.1.3/lib/omniauth/0000755000004100000410000000000012670342462020234 5ustar www-datawww-dataomniauth-remote-user-0.1.3/lib/omniauth/strategies/0000755000004100000410000000000012670342462022406 5ustar www-datawww-dataomniauth-remote-user-0.1.3/lib/omniauth/strategies/remote_user.rb0000644000004100000410000000461412670342462025271 0ustar www-datawww-datamodule OmniAuth module Strategies class RemoteUser include OmniAuth::Strategy option :internal_cookie, '_remote_user' def call(env) remote_user = env['HTTP_REMOTE_USER'] session_user = __current_user(env) if remote_user if session_user if remote_user == session_user super(env) else __logout(env) end else __login(env, remote_user) end else if session_user __logout(env) else super(env) end end end def __current_user(env) request = Rack::Request.new(env) request.cookies.has_key?(options.internal_cookie) && request.cookies[options.internal_cookie] end def __logout(env) request = Rack::Request.new(env) request.session.clear response = redirect_if_not_logging_in(request, request.path ) if response response.delete_cookie(options.internal_cookie , path: "#{request.script_name}" ) response.finish end end def __login(env, uid) request = Rack::Request.new(env) response = redirect_if_not_logging_in(request,_auth_path(request) ) if response response.set_cookie(options.internal_cookie, {value: uid, path: "#{request.script_name}", httponly: true}) response.finish end end def redirect_if_not_logging_in(request, url) if ! [ _auth_path(request), _callback_path(request) ].include?(request.path_info) response = Rack::Response.new response.redirect url response end end uid do request.env['HTTP_REMOTE_USER'] end info do user_data = request.env['HTTP_REMOTE_USER_DATA'] if user_data data = JSON.parse(user_data) data['nickname'] = uid data['firstname'] = data['name'].split()[0] data['lastname'] = data['name'].split()[1] data else {} end end def request_phase redirect _callback_path(request) end def _callback_path(request) "#{_auth_path(request)}/callback" end def _auth_path(request) "#{request.script_name}#{path_prefix}/RemoteUser" end end end end omniauth-remote-user-0.1.3/lib/omniauth/remote-user.rb0000644000004100000410000000021512670342462023026 0ustar www-datawww-datarequire 'omniauth' require 'json' module OmniAuth module Strategies autoload :RemoteUser, 'omniauth/strategies/remote_user' end end omniauth-remote-user-0.1.3/lib/omniauth-remote-user/0000755000004100000410000000000012670342462022501 5ustar www-datawww-dataomniauth-remote-user-0.1.3/lib/omniauth-remote-user/version.rb0000644000004100000410000000010412670342462024506 0ustar www-datawww-datamodule Omniauth module RemoteUser VERSION = '0.1.3' end end omniauth-remote-user-0.1.3/lib/omniauth-remote-user.rb0000644000004100000410000000010612670342462023023 0ustar www-datawww-datarequire 'omniauth-remote-user/version' require 'omniauth/remote-user' omniauth-remote-user-0.1.3/README.md0000644000004100000410000000044212670342462017121 0ustar www-datawww-data# Omniath Remote User The Omniauth Remote User gem provides a way for application to utilize a authentication with remote user HTTP header. # Instalation Include in your Gemfile ```ruby gem "omniauth-remote-user" ``` Then run `bundle install` from the command line: bundle install omniauth-remote-user-0.1.3/config.ru0000644000004100000410000000176412670342462017467 0ustar www-datawww-datarequire 'sinatra' require 'omniauth' require 'json' class MyApplication < Sinatra::Base use Rack::Session::Cookie, secret: '123' STRATEGY = 'RemoteUser' #use OmniAuth::Strategies::RemoteUser #STRATEGY = 'developer' use OmniAuth::Strategies::Developer get '/login' do redirect '/gitlab/auth/%s' % STRATEGY end get '/logout' do session[:current_user] = nil redirect '/' end post '/auth/:provider/callback' do session[:current_user] = request.env['omniauth.auth']['uid'] session[:current_user_email] = request.env['omniauth.auth']['info']['email'] session[:current_user_nickname] = request.env['omniauth.auth']['info']['nickname'] redirect '/' end get '/' do user = session[:current_user] if user info = "(%s → %s)" % [session[:current_user_email], session[:current_user_nickname]] user + info + ' logout' else 'NOT AUTHENTICATED login' end end end run MyApplication