shib-rack 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca0cc87599b9b1fbbf3ca438be67ed5f5721424a9f8336f5e3b0cea657f74855
4
- data.tar.gz: da104a3eca3c6af72ab5b6d377107835f7d7ed4593ce62f2fb9d9180cdaa6c4e
3
+ metadata.gz: 78fa3a4ee12fc6f8e41592474540ce68b901ef3f029aecbd0570f45875281559
4
+ data.tar.gz: 3758a8bc22d11331862fa010d697a5baca2a7eb2b5f67e50bc7e6e5f5f4b7ca9
5
5
  SHA512:
6
- metadata.gz: 54677c9f744f091ab69d4e28a51f4c352d8b32ba5967d4b517677288d4c285afb53328a58d68eda34c161544bcfd333cadab07f3e22525343fa62e397f7c28a1
7
- data.tar.gz: 397dd0fbec7d4d5fe73bc7eac86068fe34568fe22f9cf05d9193abc3c728c99e576ee295baffc3b6011607737af771b982dfcaf3ed1c5eaa14e920370987a3e0
6
+ metadata.gz: eb56619f465b8ef03c7e96aef94dd1ee66dd408f5452bf6c07df966faecf128553e0ed6ad329a2223ef0f8c21742681c769cd112cea44883a57e1ee1c193f707
7
+ data.tar.gz: 29c1a07bd0cc488e958fea28749f413a70781a7434085df7edcade942b2c5be2734129e077ed309f880039d979fd9a26fc8f3f871f1c1689eac25ba9d1d688d3
@@ -0,0 +1,20 @@
1
+ name: Run RSpec tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - name: Checkout code
11
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
12
+
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e3b51e0a616acc # v1.202.0
15
+
16
+ - name: Install dependencies
17
+ run: bundle install
18
+
19
+ - name: Run RSpec
20
+ run: bundle exec rspec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.6
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ publish-gem:
2
+ gem build shib-rack.gemspec
3
+ gem push shib-rack-*.gem
4
+ rm shib-rack-*.gem
data/README.md CHANGED
@@ -1,36 +1,15 @@
1
1
  # ShibRack
2
2
 
3
3
  [![Gem Version][GV img]][Gem Version]
4
- [![Build Status][BS img]][Build Status]
5
4
 
6
5
  [Gem Version]: https://rubygems.org/gems/shib-rack
7
- [Build Status]: https://codeship.com/projects/145971
8
6
 
9
7
  [GV img]: https://img.shields.io/gem/v/shib-rack.svg
10
- [BS img]: https://img.shields.io/codeship/5cdcef80-e343-0133-84a6-5a988fa7d930/develop.svg
11
8
 
12
9
  [Shibboleth SP](http://shibboleth.net) authentication plugin for Rack-based web
13
10
  applications. Contains Rails-specific extensions for consumption by Rails
14
11
  applications.
15
12
 
16
- Author: Shaun Mangelsdorf
17
-
18
- ```
19
- Copyright 2018, Australian Access Federation
20
-
21
- Licensed under the Apache License, Version 2.0 (the "License");
22
- you may not use this file except in compliance with the License.
23
- You may obtain a copy of the License at
24
-
25
- http://www.apache.org/licenses/LICENSE-2.0
26
-
27
- Unless required by applicable law or agreed to in writing, software
28
- distributed under the License is distributed on an "AS IS" BASIS,
29
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
- See the License for the specific language governing permissions and
31
- limitations under the License.
32
- ```
33
-
34
13
  ## Installation
35
14
 
36
15
  Add the `shib-rack` dependency to your application's `Gemfile`:
@@ -45,19 +24,168 @@ Use Bundler to install the dependency:
45
24
  bundle install
46
25
  ```
47
26
 
48
- TBC
27
+ Then create a Receiver class which will receive the session attributes. In development mode, `shib-rack` uses a development handler to provide example identities that you can use.
28
+
29
+ Optionally, you can also setup an error handler class.
30
+
31
+ You will need to customise this to suit your usage. Below is an example using only a limited number of attributes.
32
+
33
+ ```ruby
34
+ # frozen_string_literal: true
35
+ # Extends the Authentication Module from Shib-Rack
36
+ module Authentication
37
+ # Custom SubjectReceiver Class
38
+ class SubjectReceiver
39
+ include ShibRack::DefaultReceiver
40
+ include ShibRack::AttributeMapping
41
+
42
+ map_single_value shared_token: 'HTTP_AUEDUPERSONSHAREDTOKEN',
43
+ targeted_id: 'HTTP_TARGETED_ID',
44
+ principal_name: 'HTTP_PRINCIPALNAME'
45
+
46
+ def subject(_env, attrs)
47
+ Subject.transaction do
48
+ identifier = attrs.slice(:targeted_id)
49
+ subject = Subject.find_or_initialize_by(identifier)
50
+
51
+ subject.update!(attrs)
52
+ subject
53
+ end
54
+ end
55
+
56
+ def finish(_env)
57
+ redirect_to('/dashboard')
58
+ end
59
+ end
60
+ end
61
+ ```
62
+
63
+ ### Multiple attributes
64
+
65
+ Some attributes are multi-valued, such as `affiliation` and `scoped_affiliation`.
66
+
67
+ You can use the `map_multi_value` method for these attributes, but you will need to consider how to store them in your app. In the example below, a separate model has been used for `affiliations`.
68
+
69
+ Multi-value attributes (as with other attributes) are appended to your HTTP headers after authentication occurs. Multi-value attributes are stored in your header as a single string with each value delimited by a `;`. This method splits the string into a ruby array based on this delimiting character.
70
+
71
+ ```ruby
72
+ # frozen_string_literal: true
73
+ # Extends the Authentication Module from Shib-Rack
74
+ module Authentication
75
+ # Custom SubjectReceiver Class
76
+ class SubjectReceiver
77
+ include ShibRack::DefaultReceiver
78
+ include ShibRack::AttributeMapping
49
79
 
50
- ### Integrating with a Rack application
80
+ map_single_value shared_token: 'HTTP_AUEDUPERSONSHAREDTOKEN',
81
+ targeted_id: 'HTTP_TARGETED_ID',
82
+ principal_name: 'HTTP_PRINCIPALNAME'
51
83
 
52
- TBD
84
+ map_multi_value affiliation: 'HTTP_EDUPERSONAFFILIATION'
85
+
86
+ def subject(_env, attrs)
87
+ Subject.transaction do
88
+ identifier = attrs.slice(:targeted_id)
89
+ subject = Subject.find_or_initialize_by(identifier)
90
+
91
+ subject.update!(attrs.except(:affiliation))
92
+ update_affiliations(subject, attrs)
93
+
94
+ subject
95
+ end
96
+ end
97
+
98
+ def finish(_env)
99
+ redirect_to('/dashboard')
100
+ end
101
+
102
+ def update_affiliations(subject, attrs)
103
+ touched = []
104
+
105
+ attrs[:affiliation].each do |value|
106
+ touched << subject.affiliations.find_or_create_by!(value: value)
107
+ end
108
+
109
+ subject.affiliations.where.not(id: touched.map(&:id)).destroy_all
110
+ end
111
+ end
112
+ end
113
+ ```
53
114
 
54
115
  ### Integrating with a Rails application
55
116
 
56
- TBD
117
+ Map the `ShibRack::Engine` app to a path in your application. It is strongly recommended that you use the default path of `/auth`. In `config/routes.rb`
118
+
119
+ ```ruby
120
+ Rails.application.routes.draw do
121
+ mount ShibRack::Engine => '/auth'
122
+ end
123
+ ```
124
+
125
+ Configure the receiver, and optional error handler in `config/application.rb`
126
+
127
+ ```ruby
128
+ module MyApp
129
+ class Application < Rails::Application
130
+ # ...
131
+ config.autoload_paths << Rails.root.join('lib')
132
+ config.shib_rack.receiver = 'Authentication::SubjectReceiver'
133
+ config.shib_rack.error_handler = 'Authentication::ErrorHandler'
134
+ end
135
+ end
136
+ ```
137
+
138
+ Ensure the gem runs in development mode in `config/development.rb`
139
+
140
+ ```ruby
141
+ config.shib_rack.development_mode = true
142
+ ```
143
+
144
+ And likewise ensure the gem runs in test mode in `config/test.rb`
145
+
146
+ ```ruby
147
+ config.shib_rack.test_mode = true
148
+ ```
57
149
 
58
150
  ### Using with Capybara-style tests
59
151
 
60
- TBD
152
+ Ensure that you have configured the gem to run in test mode in `config/test.rb` (See above)
153
+
154
+ Once this has been setup, you can create a capybara-style test. See the example below which tests the login process using the test handler. This is an example only, and will vary based on your app implementation.
155
+
156
+ ```ruby
157
+ # frozen_string_literal: true
158
+ require 'rails_helper'
159
+
160
+ RSpec.feature 'Authentication Flow', type: :feature do
161
+ let(:idp_domain) { Faker::Internet.domain_name }
162
+ let(:idp) { "https://idp.#{idp_domain}/idp/shibboleth" }
163
+ let(:sp) { "https://sp.#{Faker::Internet.domain_name}/shibboleth" }
164
+ let(:name) { Faker::Name.name }
165
+
166
+ let(:attrs) do
167
+ {
168
+ 'HTTP_AUEDUPERSONSHAREDTOKEN' => SecureRandom.urlsafe_base64(20),
169
+ 'HTTP_TARGETED_ID' => "#{idp}!#{sp}!#{SecureRandom.uuid}",
170
+ 'HTTP_PRINCIPALNAME' => "#{name}@#{idp_domain}",
171
+ 'HTTP_EDUPERSONAFFILIATION' => 'staff;member'
172
+ }
173
+ end
174
+
175
+ before do
176
+ ShibRack::TestHandler.attributes = attrs
177
+ visit '/auth/login'
178
+ end
179
+
180
+ it 'User is redirected to dashboard with details displayed on initial login' do
181
+ expect(current_path).to eq('/dashboard')
182
+ expect(page).to have_content("You're logged in. Here are your details")
183
+ expect(page).to have_content(name)
184
+ expect(page).to have_content(idp_domain)
185
+ # Further checks for other attributes can be added here
186
+ end
187
+ end
188
+ ```
61
189
 
62
190
  ## Contributing
63
191
 
@@ -22,7 +22,7 @@ module ShibRack
22
22
  end
23
23
 
24
24
  def redirect_to(url)
25
- [302, { 'Location' => url }, []]
25
+ [302, { 'location' => url }, []]
26
26
  end
27
27
 
28
28
  def logout(env)
@@ -56,7 +56,7 @@ module ShibRack
56
56
  end
57
57
 
58
58
  env['rack.session']['original_params'] = params
59
- [302, { 'Location' => DevelopmentHandler.login_redirect(env) }, []]
59
+ [302, { 'location' => DevelopmentHandler.login_redirect(env) }, []]
60
60
  end
61
61
 
62
62
  def restore_original_query(env)
@@ -70,7 +70,7 @@ module ShibRack
70
70
  def development
71
71
  [
72
72
  200,
73
- { 'Content-Type' => 'text/html; charset=utf-8' },
73
+ { 'content-type' => 'text/html; charset=utf-8' },
74
74
  [development_html]
75
75
  ]
76
76
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ostruct'
4
+
3
5
  module ShibRack
4
6
  # Provides integration of shib-rack into Rails applications
5
7
  class Engine < Rails::Engine
@@ -20,7 +20,7 @@ module ShibRack
20
20
 
21
21
  def handle(_env, _exception)
22
22
  [
23
- 400, { 'Content-Type' => 'text/plain' }, [
23
+ 400, { 'content-type' => 'text/plain' }, [
24
24
  'Sorry, your attempt to log in to this service was not successful. ',
25
25
  'Please contact the service owner for assistance, and include the ',
26
26
  'link you used to access this service.'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ShibRack
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/shib-rack.gemspec CHANGED
@@ -18,17 +18,18 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'rack'
21
+ spec.add_dependency 'ostruct'
21
22
 
22
23
  spec.add_development_dependency 'aaf-gumboot'
23
24
 
24
25
  spec.add_development_dependency 'faker'
25
26
  spec.add_development_dependency 'rack-test'
26
- spec.add_development_dependency 'rails', '~> 4.2'
27
+ spec.add_development_dependency 'rails'
27
28
  spec.add_development_dependency 'sqlite3'
28
29
 
29
- spec.add_development_dependency 'bundler', '~> 1.11'
30
- spec.add_development_dependency 'rake', '~> 10.0'
31
- spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'rspec'
32
33
 
33
34
  spec.add_development_dependency 'guard'
34
35
  spec.add_development_dependency 'guard-bundler'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shib-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Mangelsdorf
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ostruct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: aaf-gumboot
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +84,16 @@ dependencies:
70
84
  name: rails
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '4.2'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '4.2'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: sqlite3
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -98,44 +112,44 @@ dependencies:
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - "~>"
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: '1.11'
117
+ version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - "~>"
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '1.11'
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - "~>"
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
- version: '10.0'
131
+ version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - "~>"
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
- version: '10.0'
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - "~>"
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: '3.0'
145
+ version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - "~>"
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: '3.0'
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: guard
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -206,20 +220,23 @@ dependencies:
206
220
  - - ">="
207
221
  - !ruby/object:Gem::Version
208
222
  version: '0'
209
- description:
223
+ description:
210
224
  email:
211
225
  - s.mangelsdorf@gmail.com
212
226
  executables: []
213
227
  extensions: []
214
228
  extra_rdoc_files: []
215
229
  files:
230
+ - ".github/workflows/.test.yaml"
216
231
  - ".gitignore"
217
232
  - ".rspec"
218
233
  - ".rubocop.yml"
234
+ - ".ruby-version"
219
235
  - ".simplecov"
220
236
  - Gemfile
221
237
  - Guardfile
222
238
  - LICENSE
239
+ - Makefile
223
240
  - README.md
224
241
  - Rakefile
225
242
  - bin/setup
@@ -238,7 +255,7 @@ files:
238
255
  homepage: https://github.com/ausaccessfed/shib-rack.git
239
256
  licenses: []
240
257
  metadata: {}
241
- post_install_message:
258
+ post_install_message:
242
259
  rdoc_options: []
243
260
  require_paths:
244
261
  - lib
@@ -253,9 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
270
  - !ruby/object:Gem::Version
254
271
  version: '0'
255
272
  requirements: []
256
- rubyforge_project:
257
- rubygems_version: 2.7.7
258
- signing_key:
273
+ rubygems_version: 3.5.22
274
+ signing_key:
259
275
  specification_version: 4
260
276
  summary: Rack middleware for Shibboleth SP authentication
261
277
  test_files: []