omniauth2-shibboleth 2.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0408fcf35d2971994f21bdbc690fd7388bc882c1d3ba9f2e4b23c236f22506dc'
4
+ data.tar.gz: 88bb49fe641312f11966f39559886e09c175eb15b644735b0b0cc3a31a3c3d5a
5
+ SHA512:
6
+ metadata.gz: c2ae2ea2d84eedfb4197c42225cb3f09186966ebc2af56f5e5d169af6dc88391fb83591b5ca6f346394409dc03dac477a6b8a82986ab7e39f17f807e00ff9749
7
+ data.tar.gz: 0bed9d200f1f8b1da20b1933adadb0fa07359ebad4c840304c658c7df93cf3ccf043804e05c86235cd409a8e19bf0aedb47c1d8aac7a3e8064027f4f6ba21a1c
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+ gem "omniauth2-shibboleth", :git => "git://github.com/arcolan/omniauth2-shibboleth.git"
data/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # OmniAuth Shibboleth strategy
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/omniauth-shibboleth.svg)](http://rubygems.org/gems/omniauth-shibboleth)
4
+ [![Build Status](https://travis-ci.org/toyokazu/omniauth-shibboleth.svg?branch=master)](https://travis-ci.org/toyokazu/omniauth-shibboleth)
5
+
6
+ OmniAuth Shibboleth strategy is an OmniAuth strategy for authenticating through Shibboleth (SAML). If you do not know OmniAuth, please visit OmniAuth wiki.
7
+
8
+ https://github.com/intridea/omniauth/wiki
9
+
10
+ The detail of the authentication middleware Shibboleth is introduced in Shibboleth wiki.
11
+
12
+ https://wiki.shibboleth.net/
13
+
14
+ OmniAuth basically works as a middleware of Rack applications. It provides environment variable named 'omniauth.auth' (auth hash) after authenticating a user. The 'auth hash' includes the user's attributes. By providing user attributes in the fixed format, applications can easily implement authentication function using multiple authentication methods.
15
+
16
+ OmniAuth Shibboleth strategy uses the 'auth hash' for providing user attributes passed by Shibboleth SP. It enables developers to use Shibboleth and the other authentication methods, including local auth, together in one application.
17
+
18
+ Currently, this document is written for Rails applications. If you tried the other environments and it requires some difficulities, please let me know in the Issues page.
19
+
20
+ https://github.com/toyokazu/omniauth-shibboleth/issues
21
+
22
+ ## Getting Started
23
+
24
+ ### Setup Gemfile and Install
25
+
26
+ % cd rails-app
27
+ % vi Gemfile
28
+ gem 'omniauth-shibboleth'
29
+ % bundle install
30
+
31
+ ### Setup Shibboleth Strategy
32
+
33
+ To use OmniAuth Shibboleth strategy as a middleware in your rails application, add the following file to your rails application initializer directory.
34
+
35
+ % vi config/initializer/omniauth.rb
36
+ Rails.application.config.middleware.use OmniAuth::Builder do
37
+ provider :shibboleth
38
+ end
39
+
40
+ % vi config/initializer/omniauth.rb
41
+ Rails.application.config.middleware.use OmniAuth::Builder do
42
+ provider :shibboleth, {
43
+ :shib_session_id_field => "Shib-Session-ID",
44
+ :shib_application_id_field => "Shib-Application-ID",
45
+ :debug => false,
46
+ :extra_fields => [
47
+ :"unscoped-affiliation",
48
+ :entitlement
49
+ ]
50
+ }
51
+ end
52
+
53
+ In the above example, 'unscoped-affiliation' and 'entitlement' attributes are additionally provided in the raw_info field. They can be referred like request.env["omniauth.auth"]["extra"]["raw_info"]["unscoped-affiliation"]. The detail of the omniauth auth hash schema is described in the following page.
54
+
55
+ https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
56
+
57
+ 'eppn' attribute is used as uid field. 'displayName' attribute is provided as request.env["omniauth.auth"]["info"]["name"].
58
+
59
+ These can be changed by :uid_field, :name_field option. You can also add any "info" fields defined in Auth-Hash-Schema by using :info_fields option.
60
+
61
+ % vi config/initializer/omniauth.rb
62
+ Rails.application.config.middleware.use OmniAuth::Builder do
63
+ provider :shibboleth, {
64
+ :uid_field => "uid",
65
+ :name_field => "displayName",
66
+ :info_fields => {
67
+ :email => "mail",
68
+ :location => "contactAddress",
69
+ :image => "photo_url",
70
+ :phone => "contactPhone"
71
+ }
72
+ }
73
+ end
74
+
75
+ In the previous example, Shibboleth strategy does not pass any :info fields and use 'uid' attribute as uid fields.
76
+
77
+ ### More flexible attribute configuration
78
+
79
+ If you need more flexible attribute definition, you can use lambda (Proc) to define your attributes. In the following example, 'uid' attribute is chosen from 'eppn' or 'mail', 'info'/'name' attribute is defined as a concatenation of 'cn' and 'sn' and 'info'/'affiliation' attribute is defined as 'affiliation'@my.localdomain. 'request_param' parameter is a method defined in OmniAuth::Shibboleth::Strategy. You can specify attribute names by downcase strings in either request_type, :env, :header and :params.
80
+
81
+ % vi config/initializer/omniauth.rb
82
+ Rails.application.config.middleware.use OmniAuth::Builder do
83
+ provider :shibboleth, {
84
+ :uid_field => lambda {|request_param| request_param.call('eppn') || request_param.call('mail')},
85
+ :name_field => lambda {|request_param| "#{request_param.call('cn')} #{request_param.call('sn')}"},
86
+ :info_fields => {
87
+ :affiliation => lambda {|request_param| "#{request_param.call('affiliation')}@my.localdomain"},
88
+ :email => "mail",
89
+ :location => "contactAddress",
90
+ :image => "photo_url",
91
+ :phone => "contactPhone"
92
+ }
93
+ }
94
+ end
95
+
96
+ ### !!!NOTICE!!! devise integration issue
97
+
98
+ When you use omniauth with devise, the omniauth configuration is applied before devise configuration and some part of the configuration overwritten by the devise's. It may not work as you assume. So thus, in that case, currently you should write your configuration only in device configuration.
99
+
100
+ config/initializers/devise.rb:
101
+ ```ruby
102
+ config.omniauth :shibboleth, {:uid_field => 'eppn',
103
+ :info_fields => {:email => 'mail', :name => 'cn', :last_name => 'sn'},
104
+ :extra_fields => [:schacHomeOrganization]
105
+ }
106
+ ```
107
+
108
+ The detail is discussed in the following thread.
109
+
110
+ https://github.com/plataformatec/devise/issues/2128
111
+
112
+
113
+ ### How to authenticate users
114
+
115
+ In your application, simply direct users to '/auth/shibboleth' to have them sign in via your company's Shibboleth SP and IdP. '/auth/shibboleth' url simply redirect users to '/auth/shibboleth/callback', so thus you must protect '/auth/shibboleth/callback' by Shibboleth SP.
116
+
117
+ Example shibd.conf:
118
+
119
+ <Location /application_path/auth/shibboleth/callback>
120
+ AuthType shibboleth
121
+ ShibRequestSetting requireSession 1
122
+ require valid-user
123
+ </Location>
124
+
125
+ Shibboleth strategy just checks the existence of Shib-Session-ID or Shib-Application-ID.
126
+
127
+ If you want to use omniauth-shibboleth without Apache or IIS, you can try **rack-saml**. It supports a part of Shibboleth SP functions.
128
+
129
+ https://github.com/toyokazu/rack-saml
130
+
131
+ Shibboleth strategy assumes the attributes are provided via environment variables because the use of ShibUseHeaders option may cause some problems. The details are discussed in the following page:
132
+
133
+ https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPSpoofChecking
134
+
135
+ To provide Shibboleth attributes via environment variables, we can not use proxy based approach, e.g. mod_proxy_balancer. Currently we can realize it by using Phusion Passenger as an application container. An example construction pattern is shown in presence_checker application (https://github.com/toyokazu/presence_checker/).
136
+
137
+ ### :request_type option
138
+
139
+ You understand the issues using ShibUseHeaders, but and yet if you want to use the proxy based approach, you can use :request_type option. This option enables us to specify what kind of parameters are used to create 'omniauth.auth' (auth hash). This option can also be used to develop your Rails application without local IdP and SP by using :params option. The option values are:
140
+
141
+ - **:env** (default) The environment variables are used to create auth hash.
142
+ - **:header** The auth hash is created from header vaiables. In the Rack middleware, since header variables are treated as environment variables like HTTP_*, the specified variables are converted as the same as header variables, HTTP_*. This :request_type is basically used for mod_proxy_balancer approach.
143
+ - **:params** The query string or POST parameters are used to create auth hash. This :request_type is basically used for development phase. You can emulate SP function by providing parameters as query string. In this case, please do not forget to add Shib-Session-ID or Shib-Application-ID value which is used to check the session is created at SP.
144
+
145
+ The following is an example configuration.
146
+
147
+ % vi config/initializer/omniauth.rb
148
+ Rails.application.config.middleware.use OmniAuth::Builder do
149
+ provider :shibboleth, { :request_type => :header }
150
+ end
151
+
152
+ If you use proxy based approach, please be sure to add ShibUseHeaders option in mod_shib configuration.
153
+
154
+ <Location /secure>
155
+ AuthType shibboleth
156
+ ShibRequestSetting requireSession 1
157
+ ShibUseHeaders On
158
+ require valid-user
159
+ </Location>
160
+
161
+ ### debug mode
162
+
163
+ When you deploy a new application, you may want to confirm the assumed attributes are correctly provided by Shibboleth SP. OmniAuth Shibboleth strategy provides a confirmation option :debug. If you set :debug true, you can see the environment variables provided at the /auth/shibboleth/callback uri.
164
+
165
+ % vi config/initializer/omniauth.rb
166
+ Rails.application.config.middleware.use OmniAuth::Builder do
167
+ provider :shibboleth, { :debug => true }
168
+ end
169
+
170
+ ### :multi_values option
171
+
172
+ If your application want to receive multiple values as one attribute, Shibboleth passes them as follows:
173
+
174
+ user2@example2.com;user1@example1.com;user3@example3.com
175
+
176
+ If your application only wants the first entry sorted by alphabetical order, you can use flexible attribute configuration as follows (since semicolons in attribute values are escaped with a backslash, escaped semicolons are skiped for splitting):
177
+
178
+ % vi config/initializer/omniauth.rb
179
+ Rails.application.config.middleware.use OmniAuth::Builder do
180
+ provider :shibboleth, {
181
+ :info_fields => {
182
+ :email => lambda {|request_param| request_param.call('email').split(/(?<!\\);/).sort[0]}
183
+ }
184
+ }
185
+ end
186
+
187
+ However, if you use device to integrate omniauth, lambda function cannot be used. In such a situation, if you still think that attribute conversions in the middleware is required, you can use :multi_values option.
188
+
189
+ - **:raw** (default) Raw multiple values are passed to the application.
190
+ - **:first** The first entry of multiple values is passed to the application.
191
+ - **lambda function** The other descriptions are regarded as lambda function written in String form. The string will be evaluated as Ruby code and used for processing multiple values in the attribute.
192
+
193
+ If you specify :first, you can obtain `user2@example.com` in the above example.
194
+
195
+ % vi config/initializer/omniauth.rb
196
+ Rails.application.config.middleware.use OmniAuth::Builder do
197
+ provider :shibboleth, {
198
+ :multi_values => :first
199
+ }
200
+ end
201
+
202
+ If you need the first attribute in alphabetical order, you can specify lambda function in String form as follows:
203
+
204
+ % vi config/initializer/omniauth.rb
205
+ Rails.application.config.middleware.use OmniAuth::Builder do
206
+ provider :shibboleth, {
207
+ :multi_values => 'lambda {|param_value| param_value.nil? ? nil : param_value.split(/(?<!\\\\);/).sort[0]}'
208
+ }
209
+ end
210
+
211
+
212
+ ## License (MIT License)
213
+
214
+ omniauth-shibboleth is released under the MIT license.
215
+
216
+ Permission is hereby granted, free of charge, to any person obtaining a copy
217
+ of this software and associated documentation files (the "Software"), to deal
218
+ in the Software without restriction, including without limitation the rights
219
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
220
+ copies of the Software, and to permit persons to whom the Software is
221
+ furnished to do so, subject to the following conditions:
222
+
223
+ The above copyright notice and this permission notice shall be included in
224
+ all copies or substantial portions of the Software.
225
+
226
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
227
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
228
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
229
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
230
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
231
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
232
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new("spec")
5
+ task :default => :spec
@@ -0,0 +1,109 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Shibboleth
4
+ include OmniAuth::Strategy
5
+
6
+ option :shib_session_id_field, 'Shib-Session-ID'
7
+ option :shib_application_id_field, 'Shib-Application-ID'
8
+ option :uid_field, 'eppn'
9
+ option :name_field, 'displayName'
10
+ option :info_fields, {}
11
+ option :extra_fields, []
12
+ option :debug, false
13
+ option :fail_with_empty_uid, false
14
+ option :request_type, :env
15
+ option :multi_values, :raw
16
+
17
+ def request_phase
18
+ [
19
+ 302,
20
+ {
21
+ 'Location' => script_name + callback_path + query_string,
22
+ 'Content-Type' => 'text/plain'
23
+ },
24
+ ["You are being redirected to Shibboleth SP/IdP for sign-in."]
25
+ ]
26
+ end
27
+
28
+ def request_params
29
+ case options.request_type
30
+ when :env, 'env', :header, 'header'
31
+ request.env
32
+ when :params, 'params'
33
+ request.params
34
+ end
35
+ end
36
+
37
+ def request_param(key)
38
+ multi_value_handler(
39
+ case options.request_type
40
+ when :env, 'env'
41
+ request.env[key]
42
+ when :header, 'header'
43
+ request.env["HTTP_#{key.upcase.gsub('-', '_')}"]
44
+ when :params, 'params'
45
+ request.params[key]
46
+ end
47
+ )
48
+ end
49
+
50
+ def multi_value_handler(param_value)
51
+ case options.multi_values
52
+ when :raw, 'raw'
53
+ param_value
54
+ when :first, 'first'
55
+ return nil if param_value.nil?
56
+ param_value.split(/(?<!\\);/).first.gsub('\\;', ';')
57
+ else
58
+ eval(options.multi_values).call(param_value)
59
+ end
60
+ end
61
+
62
+ def callback_phase
63
+ if options.debug
64
+ # dump attributes
65
+ return [
66
+ 200,
67
+ {
68
+ 'Content-Type' => 'text/plain'
69
+ },
70
+ ["!!!!! This message is generated by omniauth-shibboleth. To remove it set :debug to false. !!!!!\n#{request_params.sort.map {|i| "#{i[0]}: #{i[1]}" }.join("\n")}"]
71
+ ]
72
+ end
73
+ return fail!(:no_shibboleth_session) unless (request_param(options.shib_session_id_field.to_s) || request_param(options.shib_application_id_field.to_s))
74
+ return fail!(:empty_uid) if options.fail_with_empty_uid && option_handler(options.uid_field).empty?
75
+ super
76
+ end
77
+
78
+ def option_handler(option_field)
79
+ if option_field.class == String ||
80
+ option_field.class == Symbol
81
+ request_param(option_field.to_s)
82
+ elsif option_field.class == Proc
83
+ option_field.call(self.method(:request_param))
84
+ end
85
+ end
86
+
87
+ uid do
88
+ option_handler(options.uid_field)
89
+ end
90
+
91
+ info do
92
+ res = {
93
+ :name => option_handler(options.name_field)
94
+ }
95
+ options.info_fields.each_pair do |key, field|
96
+ res[key] = option_handler(field)
97
+ end
98
+ res
99
+ end
100
+
101
+ extra do
102
+ options.extra_fields.inject({:raw_info => {}}) do |hash, field|
103
+ hash[:raw_info][field] = request_param(field.to_s)
104
+ hash
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Shibboleth
3
+ VERSION = "2.0.0.alpha"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "omniauth2-shibboleth/version"
2
+ require "omniauth"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ autoload :Shibboleth, 'omniauth/strategies/shibboleth'
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth2-shibboleth/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth', '~> 2.1.1'
6
+
7
+ gem.add_development_dependency 'rack-test', '~> 2.1.0'
8
+ gem.add_development_dependency 'rake', '~> 13.0.6'
9
+ gem.add_development_dependency 'rspec', '~> 2.8'
10
+
11
+ gem.license = 'MIT'
12
+
13
+ gem.authors = ["Sylvain Lanoë"]
14
+ gem.email = ["sylvain@arcolan.fr"]
15
+ gem.description = %q{OmniAuth Shibboleth strategies}
16
+ gem.summary = %q{OmniAuth Shibboleth strategies for OmniAuth 2.x}
17
+ gem.homepage = "https://rubygems.org/gems/omniauth2-shibboleth"
18
+
19
+ gem.files = `find . -not \\( -regex ".*\\.git.*" -o -regex "\\./pkg.*" -o -regex "\\./spec.*" \\)`.split("\n").map{ |f| f.gsub(/^.\//, '') }
20
+ gem.test_files = `find spec/*`.split("\n")
21
+ gem.name = "omniauth2-shibboleth"
22
+ gem.require_paths = ["lib"]
23
+ gem.version = OmniAuth::Shibboleth::VERSION
24
+
25
+
26
+ end
@@ -0,0 +1,361 @@
1
+ #require 'pry-byebug'
2
+ require 'spec_helper'
3
+
4
+ def make_env(path = '/auth/shibboleth', props = {})
5
+ {
6
+ 'REQUEST_METHOD' => 'GET',
7
+ 'PATH_INFO' => path,
8
+ 'rack.session' => {},
9
+ 'rack.input' => StringIO.new('test=true')
10
+ }.merge(props)
11
+ end
12
+
13
+ def without_session_failure_path
14
+ if OmniAuth::VERSION >= "2.1" && OmniAuth::VERSION < "2.2"
15
+ "/auth/failure?message=no_shibboleth_session"
16
+ elsif OmniAuth::VERSION >= "2.2"
17
+ "/auth/failure?message=no_shibboleth_session&strategy=shibboleth"
18
+ end
19
+ end
20
+
21
+ def empty_uid_failure_path
22
+ if OmniAuth::VERSION >= "2.1" && OmniAuth::VERSION < "2.2"
23
+ "/auth/failure?message=empty_uid"
24
+ elsif OmniAuth::VERSION >= "2.2"
25
+ "/auth/failure?message=empty_uid&strategy=shibboleth"
26
+ end
27
+ end
28
+
29
+ describe OmniAuth::Strategies::Shibboleth do
30
+ let(:app){ Rack::Builder.new do |b|
31
+ b.use Rack::Session::Cookie, {:secret => "abc123"}
32
+ b.use OmniAuth::Strategies::Shibboleth
33
+ b.run lambda{|env| [200, {}, ['Not Found']]}
34
+ end.to_app }
35
+
36
+ context 'request phase' do
37
+ before do
38
+ get '/auth/shibboleth'
39
+ end
40
+
41
+ it 'is expected to redirect to callback_url' do
42
+ expect(last_response.status).to eq(302)
43
+ expect(last_response.location).to eq('/auth/shibboleth/callback')
44
+ end
45
+ end
46
+
47
+ context 'callback phase' do
48
+ context 'without Shibboleth session' do
49
+ before do
50
+ get '/auth/shibboleth/callback'
51
+ end
52
+
53
+ it 'is expected to fail to get Shib-Session-ID environment variable' do
54
+ expect(last_response.status).to eq(302)
55
+ expect(last_response.location).to eq(without_session_failure_path)
56
+ end
57
+ end
58
+
59
+ context 'with Shibboleth session' do
60
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, {}) }
61
+
62
+ it 'is expected to set default omniauth.auth fields' do
63
+ @dummy_id = 'abcdefg'
64
+ @eppn = 'test@example.com'
65
+ @display_name = 'Test User'
66
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'eppn' => @eppn, 'displayName' => @display_name)
67
+ strategy.call!(env)
68
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@eppn)
69
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
70
+ end
71
+ end
72
+
73
+ context 'with Shibboleth session and attribute options' do
74
+ let(:options){ {
75
+ :shib_session_id_field => 'Shib-Session-ID',
76
+ :shib_application_id_field => 'Shib-Application-ID',
77
+ :uid_field => :uid,
78
+ :name_field => :sn,
79
+ :info_fields => {},
80
+ :extra_fields => [:o, :affiliation] } }
81
+ let(:app){ lambda{|env| [404, {}, ['Not Found']]}}
82
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
83
+
84
+ it 'is expected to set specified omniauth.auth fields' do
85
+ @dummy_id = 'abcdefg'
86
+ @uid = 'test'
87
+ @sn = 'User'
88
+ @organization = 'Test Corporation'
89
+ @affiliation = 'faculty'
90
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'sn' => @sn, 'o' => @organization, 'affiliation' => @affiliation)
91
+ strategy.call!(env)
92
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
93
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['o']).to eq(@organization)
94
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['affiliation']).to eq(@affiliation)
95
+ end
96
+ end
97
+
98
+ context 'with debug options' do
99
+ let(:options) { { :debug => true } }
100
+ let(:app){ lambda{|env| [404, {}, ['Not Found']]}}
101
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
102
+
103
+ it 'is expected to raise environment variables' do
104
+ @dummy_id = 'abcdefg'
105
+ @eppn = 'test@example.com'
106
+ @display_name = 'Test User'
107
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'eppn' => @eppn, 'displayName' => @display_name)
108
+ response = strategy.call!(env)
109
+ expect(response[0]).to eq(200)
110
+ end
111
+ end
112
+
113
+ context 'with request_type = :header' do
114
+ let(:options){ {
115
+ :request_type => :header,
116
+ :shib_session_id_field => 'Shib-Session-ID',
117
+ :shib_application_id_field => 'Shib-Application-ID',
118
+ :uid_field => :uid,
119
+ :name_field => :displayName,
120
+ :info_fields => {},
121
+ :extra_fields => [:o, :affiliation] } }
122
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
123
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
124
+
125
+ it 'is expected to handle header variables' do
126
+ @dummy_id = 'abcdefg'
127
+ @display_name = 'Test User'
128
+ @uid = 'test'
129
+ @organization = 'Test Corporation'
130
+ @affiliation = 'faculty'
131
+ env = make_env('/auth/shibboleth/callback', 'HTTP_SHIB_SESSION_ID' => @dummy_id, 'HTTP_DISPLAYNAME' => @display_name, 'HTTP_UID' => @uid, 'HTTP_O' => @organization, 'HTTP_AFFILIATION' => @affiliation)
132
+ strategy.call!(env)
133
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
134
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
135
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['o']).to eq(@organization)
136
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['affiliation']).to eq(@affiliation)
137
+ end
138
+ end
139
+
140
+ context "with request_type = 'header'" do
141
+ let(:options){ {
142
+ :request_type => 'header',
143
+ :shib_session_id_field => 'Shib-Session-ID',
144
+ :shib_application_id_field => 'Shib-Application-ID',
145
+ :uid_field => :uid,
146
+ :name_field => :displayName,
147
+ :info_fields => {},
148
+ :extra_fields => [:o, :affiliation] } }
149
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
150
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
151
+
152
+ it 'is expected to handle header variables' do
153
+ @dummy_id = 'abcdefg'
154
+ @display_name = 'Test User'
155
+ @uid = 'test'
156
+ @organization = 'Test Corporation'
157
+ @affiliation = 'faculty'
158
+ env = make_env('/auth/shibboleth/callback', 'HTTP_SHIB_SESSION_ID' => @dummy_id, 'HTTP_DISPLAYNAME' => @display_name, 'HTTP_UID' => @uid, 'HTTP_O' => @organization, 'HTTP_AFFILIATION' => @affiliation)
159
+ strategy.call!(env)
160
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
161
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
162
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['o']).to eq(@organization)
163
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['affiliation']).to eq(@affiliation)
164
+ end
165
+ end
166
+
167
+ context 'with request_type = :params' do
168
+ let(:options){ {
169
+ :request_type => :params,
170
+ :shib_session_id_field => 'Shib-Session-ID',
171
+ :shib_application_id_field => 'Shib-Application-ID',
172
+ :uid_field => :uid,
173
+ :name_field => :displayName,
174
+ :info_fields => {},
175
+ :extra_fields => [:o, :affiliation] } }
176
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
177
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
178
+
179
+ it 'is expected to handle params variables' do
180
+ @dummy_id = 'abcdefg'
181
+ @display_name = 'Test User'
182
+ @uid = 'test'
183
+ @organization = 'Test Corporation'
184
+ @affiliation = 'faculty'
185
+ env = make_env('/auth/shibboleth/callback', 'QUERY_STRING' => "Shib-Session-ID=#{@dummy_id}&uid=#{@uid}&displayName=#{@display_name}&o=#{@organization}&affiliation=#{@affiliation}")
186
+ strategy.call!(env)
187
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
188
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
189
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['o']).to eq(@organization)
190
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['affiliation']).to eq(@affiliation)
191
+ end
192
+ end
193
+
194
+ context 'with Proc option' do
195
+ let(:options){ {
196
+ :request_type => :env,
197
+ :shib_session_id_field => 'Shib-Session-ID',
198
+ :shib_application_id_field => 'Shib-Application-ID',
199
+ :uid_field => lambda {|request_param| request_param.call('eppn') || request_param.call('mail')},
200
+ :name_field => lambda {|request_param| "#{request_param.call('cn')} #{request_param.call('sn')}"},
201
+ :info_fields => {:affiliation => lambda {|request_param| "#{request_param.call('affiliation')}@my.localdomain" }},
202
+ :extra_fields => [:o, :affiliation] } }
203
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
204
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
205
+
206
+ it 'is expected to have eppn as uid and cn + sn as name field.' do
207
+ @dummy_id = 'abcdefg'
208
+ @display_name = 'Test User'
209
+ @uid = 'test'
210
+ @eppn = 'test@my.localdomain'
211
+ @cn = 'Test'
212
+ @sn = 'User'
213
+ @organization = 'Test Corporation'
214
+ @affiliation = 'faculty'
215
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'eppn' => @eppn, 'cn' => @cn, 'sn' => @sn, 'o' => @organization, 'affiliation' => @affiliation)
216
+ strategy.call!(env)
217
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@eppn)
218
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq("#{@cn} #{@sn}")
219
+ expect(strategy.env['omniauth.auth']['info']['affiliation']).to eq("#{@affiliation}@my.localdomain")
220
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['o']).to eq(@organization)
221
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['affiliation']).to eq(@affiliation)
222
+ end
223
+
224
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
225
+ it 'is expected to have mail as uid and cn + sn as name field.' do
226
+ @dummy_id = 'abcdefg'
227
+ @display_name = 'Test User'
228
+ @uid = 'test'
229
+ @mail = 'test@my.localdomain'
230
+ @cn = 'Test'
231
+ @sn = 'User'
232
+ @organization = 'Test Corporation'
233
+ @affiliation = 'faculty'
234
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'mail' => @mail, 'cn' => @cn, 'sn' => @sn, 'o' => @organization, 'affiliation' => @affiliation)
235
+ strategy.call!(env)
236
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@mail)
237
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq("#{@cn} #{@sn}")
238
+ expect(strategy.env['omniauth.auth']['info']['affiliation']).to eq("#{@affiliation}@my.localdomain")
239
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['o']).to eq(@organization)
240
+ expect(strategy.env['omniauth.auth']['extra']['raw_info']['affiliation']).to eq(@affiliation)
241
+ end
242
+ end
243
+
244
+ context 'empty uid with :fail_with_empty_uid = false' do
245
+ let(:options){ {
246
+ :request_type => :env,
247
+ :fail_with_empty_uid => false,
248
+ :uid_field => :uid,
249
+ :name_field => :displayName,
250
+ :info_fields => {} } }
251
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
252
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
253
+
254
+ it 'is expected to output null (empty) uid as it is' do
255
+ @dummy_id = 'abcdefg'
256
+ @display_name = 'Test User'
257
+ @uid = ''
258
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'displayName' => @display_name)
259
+ strategy.call!(env)
260
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
261
+ end
262
+ end
263
+
264
+ context 'empty uid with :fail_with_empty_uid = true' do
265
+ let(:options){ {
266
+ :request_type => :env,
267
+ :fail_with_empty_uid => true,
268
+ :shib_session_id_field => 'Shib-Session-ID',
269
+ :shib_application_id_field => 'Shib-Application-ID',
270
+ :uid_field => :uid,
271
+ :name_field => :displayName,
272
+ :info_fields => {} } }
273
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
274
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
275
+
276
+ it 'is expected to fail because of the empty uid' do
277
+ @dummy_id = 'abcdefg'
278
+ @display_name = 'Test User'
279
+ @uid = ''
280
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'displayName' => @display_name)
281
+ response = strategy.call!(env)
282
+ expect(response[0]).to eq(302)
283
+ expect(response[1]["Location"]).to eq(empty_uid_failure_path)
284
+ end
285
+ end
286
+
287
+ context 'with :multi_values => :raw' do
288
+ let(:options){ {
289
+ :request_type => :env,
290
+ :shib_session_id_field => 'Shib-Session-ID',
291
+ :shib_application_id_field => 'Shib-Application-ID',
292
+ :uid_field => :uid,
293
+ :name_field => :displayName,
294
+ :info_fields => {:email => "mail"} } }
295
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
296
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
297
+
298
+ it 'is expected to return the raw value' do
299
+ @dummy_id = 'abcdefg'
300
+ @display_name = 'Test User'
301
+ @uid = 'test'
302
+ @mail = 'test2\;hoge@example.com;test1\;hoge@example.com;test3\;hoge@example.com'
303
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'displayName' => @display_name, 'mail' => @mail)
304
+ strategy.call!(env)
305
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
306
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
307
+ expect(strategy.env['omniauth.auth']['info']['email']).to eq(@mail)
308
+ end
309
+ end
310
+
311
+ context 'with :multi_values => :first' do
312
+ let(:options){ {
313
+ :multi_values => :first,
314
+ :request_type => :env,
315
+ :shib_session_id_field => 'Shib-Session-ID',
316
+ :shib_application_id_field => 'Shib-Application-ID',
317
+ :uid_field => :uid,
318
+ :name_field => :displayName,
319
+ :info_fields => {:email => "mail"} } }
320
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
321
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
322
+
323
+ it 'is expected return the first value by specifying :first' do
324
+ @dummy_id = 'abcdefg'
325
+ @display_name = 'Test User'
326
+ @uid = 'test'
327
+ @mail = 'test2\;hoge@example.com;test1\;hoge@example.com;test3\;hoge@example.com'
328
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'displayName' => @display_name, 'mail' => @mail)
329
+ strategy.call!(env)
330
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
331
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
332
+ expect(strategy.env['omniauth.auth']['info']['email']).to eq('test2;hoge@example.com')
333
+ end
334
+ end
335
+
336
+ context 'with :multi_values => lambda function' do
337
+ let(:options){ {
338
+ :multi_values => "lambda {|param_value| param_value.nil? ? nil : param_value.split(/(?<!\\\\);/).sort[0].gsub('\\;',';')}",
339
+ :request_type => :env,
340
+ :shib_session_id_field => 'Shib-Session-ID',
341
+ :shib_application_id_field => 'Shib-Application-ID',
342
+ :uid_field => :uid,
343
+ :name_field => :displayName,
344
+ :info_fields => {:email => "mail"} } }
345
+ let(:app){ lambda{|env| [200, {}, ['OK']]}}
346
+ let(:strategy){ OmniAuth::Strategies::Shibboleth.new(app, options) }
347
+ it 'is expected return the processed value by specifying lambda function' do
348
+ @dummy_id = 'abcdefg'
349
+ @display_name = 'Test User'
350
+ @uid = 'test'
351
+ @mail = 'test2\;hoge@example.com;test1\;hoge@example.com;test3\;hoge@example.com'
352
+ env = make_env('/auth/shibboleth/callback', 'Shib-Session-ID' => @dummy_id, 'uid' => @uid, 'displayName' => @display_name, 'mail' => @mail)
353
+ strategy.call!(env)
354
+ expect(strategy.env['omniauth.auth']['uid']).to eq(@uid)
355
+ expect(strategy.env['omniauth.auth']['info']['name']).to eq(@display_name)
356
+ expect(strategy.env['omniauth.auth']['info']['email']).to eq('test1;hoge@example.com')
357
+ end
358
+ end
359
+
360
+ end
361
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+ require 'omniauth'
4
+ require 'omniauth/version'
5
+ require 'omniauth2-shibboleth'
6
+
7
+ RSpec.configure do |config|
8
+ config.include Rack::Test::Methods
9
+ config.color = true
10
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth2-shibboleth
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Sylvain Lanoë
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-test
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 13.0.6
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 13.0.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.8'
69
+ description: OmniAuth Shibboleth strategies
70
+ email:
71
+ - sylvain@arcolan.fr
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - README.md
78
+ - Rakefile
79
+ - lib/omniauth/strategies/shibboleth.rb
80
+ - lib/omniauth2-shibboleth.rb
81
+ - lib/omniauth2-shibboleth/version.rb
82
+ - omniauth2-shibboleth.gemspec
83
+ - spec/omniauth/strategies/shibboleth_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: https://rubygems.org/gems/omniauth2-shibboleth
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.1
103
+ requirements: []
104
+ rubygems_version: 3.0.3.1
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: OmniAuth Shibboleth strategies for OmniAuth 2.x
108
+ test_files:
109
+ - spec/omniauth/strategies/shibboleth_spec.rb
110
+ - spec/spec_helper.rb