Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The plugin can take any Tequila parameter #3

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
rvm:
- 1.9.2
- 1.9.3
- 2.3.8
- 2.5.5
- 2.6.3
branches:
only:
- master
- develop
before_install:
- gem install bundler
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ OmniAuth Tequila authenticates with the EPFL server over SSL by default. However
* `ca_path` - Optional when `ssl` is `true`. Sets path of a CA certification directory. See [Net::HTTP][net_http] for more details
* `uid_field` - The user data attribute to use as your user's unique identifier. Defaults to `'uniqueid'` (which contains the user's SCIPER number when using EPFL's Tequila server)
* `request_info` - Hash that maps user attributes from Tequila to the [OmniAuth schema][omniauth_schema]. Defaults to `{ :name => 'displayname' }` (which is the user's full name when using EPFL's Tequila server)
* `additional_parameters` - Hash that takes key - value pairs for any other parameter than those listed above. Defaults to `{}` (Empty hash)
* `additional_parameters` - Hash that takes key - value pairs for any other parameter than those listed above. Defaults to `{}` (Empty hash)
* `switchaai` - true to enable switchaai login. Defaults to `false`.

If you encounter problems wih SSL certificates you may want to set the `ca_path` parameter or activate `disable_ssl_verification` (not recommended).

Expand Down
24 changes: 21 additions & 3 deletions lib/omniauth/strategies/tequila.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'omniauth/strategy'
require 'addressable/uri'
require 'net/http'

module OmniAuth
module Strategies
Expand All @@ -14,13 +15,15 @@ class TequilaFail < StandardError; end
option :name, :tequila # Required property by OmniAuth::Strategy

option :host, 'tequila.epfl.ch'
option :require_group, 'my-group'
option :require_group, nil
option :service_name, 'Omniauth'
option :port, nil
option :path, '/cgi-bin/tequila'
option :ssl, true
option :uid_field, :uniqueid
option :request_info, { :name => 'displayname' }
option :switchaai, false
option :additional_parameters, {}

# As required by https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
info do
Expand All @@ -32,7 +35,7 @@ class TequilaFail < StandardError; end
end

uid do
raw_info[ @options[:uid_field].to_s ]
raw_info[ @options[:uid_field].to_s ]
end

def callback_phase
Expand All @@ -56,6 +59,11 @@ def callback_phase
return fail!(:invalid_info, TequilaFail.new('Invalid info from Tequila'))
end

# Normalize UID for EPFL
if auth_hash.uid.end_with? '@epfl.ch'
auth_hash.uid.delete_suffix! '@epfl.ch'
end

super
end

Expand Down Expand Up @@ -95,7 +103,17 @@ def get_request_key
# NB: You might want to set the service and required group yourself.
request_fields = @options[:request_info].values << @options[:uid_field]
body = 'urlaccess=' + callback_url + "\nservice=" + @options[:service_name] + "\n" +
'request=' + request_fields.join(',') + "\nrequire=group=" + @options[:require_group]
'request=' + request_fields.join(',')
if @options[:require_group]
body += "\nrequire=group=" + @options[:require_group]
end

if @options[:switchaai]
body += "\nallows=categorie=shibboleth"
end

@options[:additional_parameters].each { |param, value| body += "\n" + param + "=" + value}

tequila_post '/createrequest', body
end

Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth/tequila/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Omniauth
module Tequila
VERSION = '0.0.3'
VERSION = '1.0.0'
end
end
4 changes: 2 additions & 2 deletions omniauth-tequila.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ EOF
gem.require_paths = ['lib']
gem.version = Omniauth::Tequila::VERSION

gem.add_dependency 'omniauth', '~> 1.2.0'
gem.add_dependency 'omniauth', '>= 1.2.0'
gem.add_dependency 'addressable', '~> 2.3'

gem.add_development_dependency 'rake', '~> 0.9'
gem.add_development_dependency 'webmock', '~> 1.8.11'
gem.add_development_dependency 'webmock', '~> 2.3.2'
gem.add_development_dependency 'simplecov', '~> 0.7.1'
gem.add_development_dependency 'rspec', '~> 2.11'
gem.add_development_dependency 'rack-test', '~> 0.6'
Expand Down
4 changes: 2 additions & 2 deletions spec/omniauth/strategies/tequila_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def app
it 'points to the EPFL server over SSL' do
should include('ssl' => true)
should include('host' => 'tequila.epfl.ch')
should include('require_group' => 'my-group')
should include('require_group' => nil)
should include('service_name' => 'Omniauth')
should include('port' => nil)
should include('path' => '/cgi-bin/tequila')
Expand Down Expand Up @@ -62,7 +62,7 @@ def app
subject { last_response }
it { should be_redirect }
it 'should redirect to the Tequila server' do
subject.headers['Location'].should == 'http://tequila.example.org:8080/application/path/requestauth?' +
subject.headers['Location'].should == 'http://tequila.example.org:8080/application/path/requestauth?' +
'requestkey=shkfe31zsy3ow7sgnfv2e2q164cbf1to'
end
end
Expand Down