omniauth-remote-user-0.1.3/ 0000755 0000041 0000041 00000000000 12670342462 015642 5 ustar www-data www-data omniauth-remote-user-0.1.3/Rakefile 0000644 0000041 0000041 00000000143 12670342462 017305 0 ustar www-data www-data require 'bundler'
Bundler::GemHelper.install_tasks
task :default => :spec
task :test => :spec
omniauth-remote-user-0.1.3/Gemfile 0000644 0000041 0000041 00000000376 12670342462 017143 0 ustar www-data www-data source "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.gemspec 0000644 0000041 0000041 00000002004 12670342462 023274 0 ustar www-data www-data require 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/ 0000755 0000041 0000041 00000000000 12670342462 016574 5 ustar www-data www-data omniauth-remote-user-0.1.3/spec/omniauth/ 0000755 0000041 0000041 00000000000 12670342462 020420 5 ustar www-data www-data omniauth-remote-user-0.1.3/spec/omniauth/strategies/ 0000755 0000041 0000041 00000000000 12670342462 022572 5 ustar www-data www-data omniauth-remote-user-0.1.3/spec/omniauth/strategies/remote_user_spec.rb 0000644 0000041 0000041 00000007413 12670342462 026467 0 ustar www-data www-data require '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.rb 0000644 0000041 0000041 00000001134 12670342462 021411 0 ustar www-data www-data if 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.md 0000644 0000041 0000041 00000002172 12670342462 017250 0 ustar www-data www-data Copyright © 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/ 0000755 0000041 0000041 00000000000 12670342462 016410 5 ustar www-data www-data omniauth-remote-user-0.1.3/lib/omniauth/ 0000755 0000041 0000041 00000000000 12670342462 020234 5 ustar www-data www-data omniauth-remote-user-0.1.3/lib/omniauth/strategies/ 0000755 0000041 0000041 00000000000 12670342462 022406 5 ustar www-data www-data omniauth-remote-user-0.1.3/lib/omniauth/strategies/remote_user.rb 0000644 0000041 0000041 00000004614 12670342462 025271 0 ustar www-data www-data module 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.rb 0000644 0000041 0000041 00000000215 12670342462 023026 0 ustar www-data www-data require '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/ 0000755 0000041 0000041 00000000000 12670342462 022501 5 ustar www-data www-data omniauth-remote-user-0.1.3/lib/omniauth-remote-user/version.rb 0000644 0000041 0000041 00000000104 12670342462 024506 0 ustar www-data www-data module Omniauth
module RemoteUser
VERSION = '0.1.3'
end
end
omniauth-remote-user-0.1.3/lib/omniauth-remote-user.rb 0000644 0000041 0000041 00000000106 12670342462 023023 0 ustar www-data www-data require 'omniauth-remote-user/version'
require 'omniauth/remote-user'
omniauth-remote-user-0.1.3/README.md 0000644 0000041 0000041 00000000442 12670342462 017121 0 ustar www-data www-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.ru 0000644 0000041 0000041 00000001764 12670342462 017467 0 ustar www-data www-data require '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