devise_remote 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +177 -0
- data/README.md +45 -0
- data/Rakefile +21 -0
- data/app/controllers/devise_remote/application_controller.rb +7 -0
- data/app/controllers/devise_remote/sessions_controller.rb +24 -0
- data/config/routes.rb +7 -0
- data/lib/devise/models/http_header_authenticatable.rb +11 -0
- data/lib/devise/strategies/http_header_authenticatable.rb +29 -0
- data/lib/devise_remote.rb +28 -0
- data/lib/devise_remote/engine.rb +7 -0
- data/lib/devise_remote/http_header_authenticatable_behavior.rb +41 -0
- data/lib/devise_remote/version.rb +5 -0
- data/lib/generators/devise_remote/install_generator.rb +56 -0
- data/lib/generators/devise_remote/login_migration_generator.rb +25 -0
- data/lib/generators/devise_remote/templates/add_login_template.erb +9 -0
- data/lib/generators/devise_remote/templates/devise_remote.erb +22 -0
- metadata +229 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 971d928c9b14f8326f88000f2ea306b11a2c6d85623b4503b16eea21d486cb82
|
|
4
|
+
data.tar.gz: 4a85e03a037e8b7cafd99b261e9b0fe6b2014a5e21abc1a200f425932c9d815d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 29c4cd8f61de433e0de513365d8ccb7267ceb570060c8b009a53d1ac2af2e500f4cede316b4f54bdbbcfd946b40ca00fdfe7d065a7fce8335e41870e5bf095b3
|
|
7
|
+
data.tar.gz: 35131b20b40709dc1a9c76a50ac4c5281e4eda51b15565ef179858858b2f08ef6b9057237453d01f1e1efc9b132a29c364c06555e339f8d76715a345d9dd1ecf
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
data/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# DeviseRemote
|
|
2
|
+
|
|
3
|
+
Using Devise, this allows your application to authenticate with a remote service such
|
|
4
|
+
as LDAP, Shibboleth, or any other service that supplies a user's information via
|
|
5
|
+
HTTP headers.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'devise_remote'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install devise_remote
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
DeviseRemote uses much of Devise's generators. Using it with in a new Rails application should
|
|
26
|
+
only require one command:
|
|
27
|
+
|
|
28
|
+
$ bundle exec rails g devise_remote:install NAME
|
|
29
|
+
|
|
30
|
+
Where `NAME` is the ActiveRecord class you'd like to use for your user. The typical
|
|
31
|
+
class is `User` although this is not assumed as a default and you must provide one yourself.
|
|
32
|
+
|
|
33
|
+
After that, you'll need to get your controllers to authenticate by including:
|
|
34
|
+
|
|
35
|
+
before_action :authenticate_user!
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
40
|
+
|
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
42
|
+
|
|
43
|
+
## Contributing
|
|
44
|
+
|
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/devise_remote.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
require 'engine_cart/rake_task'
|
|
6
|
+
require 'rubocop/rake_task'
|
|
7
|
+
|
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
9
|
+
|
|
10
|
+
desc 'Run style checker'
|
|
11
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
|
12
|
+
task.requires << 'rubocop-rspec'
|
|
13
|
+
task.fail_on_error = true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
desc 'Run continuous integration build'
|
|
17
|
+
task ci: ['rubocop', 'engine_cart:generate'] do
|
|
18
|
+
Rake::Task['spec'].invoke
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
task default: :ci
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DeviseRemote
|
|
4
|
+
class SessionsController < ApplicationController
|
|
5
|
+
# @note Adapted from https://github.com/cosignweblogin/cosign/blob/master/scripts/logout/logout.php
|
|
6
|
+
def destroy
|
|
7
|
+
before_destroy
|
|
8
|
+
cookies.delete(request.env['COSIGN_SERVICE']) if request.env['COSIGN_SERVICE']
|
|
9
|
+
redirect_to(DeviseRemote.destroy_redirect_url)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def new
|
|
13
|
+
redirect_url = session['user_return_to']
|
|
14
|
+
session['user_return_to'] = nil if redirect_url # clear so we do not get it next time
|
|
15
|
+
webaccess = DeviseRemote.web_access_url
|
|
16
|
+
dashboard = DeviseRemote.new_session_redirect_url
|
|
17
|
+
redirect_to webaccess + '&' + (redirect_url.blank? ? dashboard : redirect_url)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @note Preprend a module to this controller in order to override this method in your
|
|
21
|
+
# local application for additions such as expiring local sessions, etc.
|
|
22
|
+
def before_destroy; end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Default strategy for signing in a user, based on their email and password in the database.
|
|
4
|
+
module Devise
|
|
5
|
+
module Strategies
|
|
6
|
+
class HttpHeaderAuthenticatable < ::Devise::Strategies::Base
|
|
7
|
+
include DeviseRemote::HttpHeaderAuthenticatableBehavior
|
|
8
|
+
|
|
9
|
+
# Called if the user doesn't already have a rails session cookie
|
|
10
|
+
def valid?
|
|
11
|
+
valid_user?(request.headers)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def authenticate!
|
|
15
|
+
user = remote_user(request.headers)
|
|
16
|
+
if user.present?
|
|
17
|
+
u = User.find_by(login: user)
|
|
18
|
+
if u.nil?
|
|
19
|
+
u = User.create(login: user, email: user)
|
|
20
|
+
u.populate_attributes if u.respond_to?(:populate_attributes)
|
|
21
|
+
end
|
|
22
|
+
success!(u)
|
|
23
|
+
else
|
|
24
|
+
fail!
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'devise_remote/engine'
|
|
4
|
+
require 'devise_remote/version'
|
|
5
|
+
require 'devise'
|
|
6
|
+
|
|
7
|
+
module DeviseRemote
|
|
8
|
+
autoload :HttpHeaderAuthenticatableBehavior, 'devise_remote/http_header_authenticatable_behavior'
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
attr_accessor :destroy_redirect_url, :new_session_redirect_url, :web_access_url
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @note Mimics the same configuration process with Devise
|
|
15
|
+
def self.setup
|
|
16
|
+
yield self
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module Devise
|
|
21
|
+
module Models
|
|
22
|
+
autoload :HttpHeaderAuthenticatable, 'devise/models/http_header_authenticatable'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module Strategies
|
|
26
|
+
autoload :HttpHeaderAuthenticatable, 'devise/strategies/http_header_authenticatable'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Shared behavior for determining if a user is valid based on the headers passed
|
|
4
|
+
# into the Rails application from the authenticating service. At Penn State, this
|
|
5
|
+
# typically happens via WebAccess. Once the user is authenticated, the user's
|
|
6
|
+
# network id (ex. abc123) is passed to the Passenger instance running the Rails
|
|
7
|
+
# application as an HTTP header. This module reads the headers to determine
|
|
8
|
+
# if there is a valid user present.
|
|
9
|
+
#
|
|
10
|
+
# We can include this module in controllers to determine if user's are valid. This
|
|
11
|
+
# is useful when making a public versus authenticated decision.
|
|
12
|
+
#
|
|
13
|
+
# @example
|
|
14
|
+
# class ApplicationController < ActionController::Base
|
|
15
|
+
# include Devise::Remote::HttpHeaderAuthenticatableBehavior
|
|
16
|
+
# end
|
|
17
|
+
|
|
18
|
+
module DeviseRemote
|
|
19
|
+
module HttpHeaderAuthenticatableBehavior
|
|
20
|
+
# @param [Hash] headers from ActionDispatch::Request#headers
|
|
21
|
+
# @return [Boolean]
|
|
22
|
+
# @note Called if the user doesn't already have a rails session cookie
|
|
23
|
+
def valid_user?(headers)
|
|
24
|
+
remote_user(headers).present?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
# @note In production, only check for REMOTE_USER. HTTP_ is removed from the variable before
|
|
30
|
+
# it is passed to the application. In test or development, this may or may not
|
|
31
|
+
# happen depending on the setup or testing framework, so we allow both. This allows for
|
|
32
|
+
# ModHeader and other browser plugins to be used in development mode.
|
|
33
|
+
def remote_user(headers)
|
|
34
|
+
if Rails.env.production?
|
|
35
|
+
headers.fetch('REMOTE_USER', nil)
|
|
36
|
+
else
|
|
37
|
+
headers.fetch('REMOTE_USER', nil) || headers.fetch('HTTP_REMOTE_USER', nil)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class DeviseRemote::InstallGenerator < Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def install_devise
|
|
7
|
+
invoke 'devise:install'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def generate_model
|
|
11
|
+
invoke 'devise', [name]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_login_to_devise
|
|
15
|
+
invoke 'devise_remote:login_migration', [name]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_initializer
|
|
19
|
+
template 'devise_remote.erb', 'config/initializers/devise_remote.rb'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_authentication
|
|
23
|
+
controller_path = 'app/controllers/application_controller.rb'
|
|
24
|
+
if File.exist?(controller_path)
|
|
25
|
+
inject_into_file controller_path, after: "class ApplicationController < ActionController::Base\n" do
|
|
26
|
+
"\t# Added by DeviseRemote to authenticate all incoming requests\n"
|
|
27
|
+
"\tbefore_action :authenticate_user!\n"
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
say_status 'warning', <<-TEXT.strip_heredoc, :yellow
|
|
31
|
+
ApplicationController not found.
|
|
32
|
+
===============================================================================
|
|
33
|
+
You will need to add the following to one of your controllers:
|
|
34
|
+
|
|
35
|
+
before_action :authenticate_user!
|
|
36
|
+
|
|
37
|
+
See the Devise's README for more information.
|
|
38
|
+
===============================================================================
|
|
39
|
+
TEXT
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update_model
|
|
44
|
+
model_path = "app/models/#{name.downcase}.rb"
|
|
45
|
+
comment_lines model_path, /able/
|
|
46
|
+
inject_into_file model_path, after: 'class User < ApplicationRecord' do
|
|
47
|
+
"\n\tdevise :http_header_authenticatable\n"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def add_routes
|
|
52
|
+
inject_into_file 'config/routes.rb', after: 'Rails.application.routes.draw do' do
|
|
53
|
+
"\n\tmount DeviseRemote::Engine => '/devise_remote'\n"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators/active_record'
|
|
4
|
+
|
|
5
|
+
class DeviseRemote::LoginMigrationGenerator < ActiveRecord::Generators::Base
|
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
7
|
+
|
|
8
|
+
def add_login_to_devise
|
|
9
|
+
migration_template 'add_login_template.erb',
|
|
10
|
+
"#{migration_path}/add_login_to_#{table_name}.rb",
|
|
11
|
+
migration_version: migration_version
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def migration_path
|
|
17
|
+
File.join('db', 'migrate')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def migration_version
|
|
21
|
+
if Rails.version.start_with?('5')
|
|
22
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class AddLoginTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
|
2
|
+
|
|
3
|
+
def change
|
|
4
|
+
add_column :<%= table_name %>, :login, :string, null: false, default: ''
|
|
5
|
+
change_column :<%= table_name %>, :email, :string, null:true
|
|
6
|
+
change_column :<%= table_name %>, :encrypted_password, :string, null: true
|
|
7
|
+
add_index :<%= table_name %>, :login, unique:true
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Warden::Strategies.add(:http_header_authenticatable, Devise::Strategies::HttpHeaderAuthenticatable)
|
|
2
|
+
|
|
3
|
+
Devise.setup do |config|
|
|
4
|
+
config.warden do |manager|
|
|
5
|
+
manager.default_strategies(:scope => :<%= name.downcase %>).unshift :http_header_authenticatable
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
DeviseRemote.setup do |config|
|
|
10
|
+
# Specify the url to redirect to when a session has been destroyed and the user
|
|
11
|
+
# has logged out of the remote authentication service.
|
|
12
|
+
config.destroy_redirect_url = '/'
|
|
13
|
+
|
|
14
|
+
# Specify the url to redirect to once a user has authenticated to the remote servce.
|
|
15
|
+
# This is ignored if there is a "user_return_to" value in the session. This enables
|
|
16
|
+
# users to return to the page they were originally on if they authenticated during
|
|
17
|
+
# an existing session.
|
|
18
|
+
config.new_session_redirect_url = '/'
|
|
19
|
+
|
|
20
|
+
# Specify the url of your remote authentication service, such as Cosign or Shibboleth.
|
|
21
|
+
config.web_access_url = 'https://my.access.service'
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: devise_remote
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Carolyn Cole, Adam Wead
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: devise
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rails
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '5.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '5.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.16'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.16'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: byebug
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: database_cleaner
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.6'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.6'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: pry-byebug
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.5'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.5'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rake
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '10.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '10.0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rspec
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '3.0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '3.0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: rspec-rails
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - "~>"
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '3.0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - "~>"
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '3.0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: rubocop
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - "~>"
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: 0.50.0
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - "~>"
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: 0.50.0
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: rubocop-rspec
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - "~>"
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: 1.17.1
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - "~>"
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: 1.17.1
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: sqlite3
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - "~>"
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '1.3'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - "~>"
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '1.3'
|
|
181
|
+
description: Allows Devise to authenticate users from central-authentication services
|
|
182
|
+
like LDAP and Shibboleth.
|
|
183
|
+
email:
|
|
184
|
+
- cam156@psu.edu, agw13@psu.edu
|
|
185
|
+
executables: []
|
|
186
|
+
extensions: []
|
|
187
|
+
extra_rdoc_files: []
|
|
188
|
+
files:
|
|
189
|
+
- LICENSE.md
|
|
190
|
+
- README.md
|
|
191
|
+
- Rakefile
|
|
192
|
+
- app/controllers/devise_remote/application_controller.rb
|
|
193
|
+
- app/controllers/devise_remote/sessions_controller.rb
|
|
194
|
+
- config/routes.rb
|
|
195
|
+
- lib/devise/models/http_header_authenticatable.rb
|
|
196
|
+
- lib/devise/strategies/http_header_authenticatable.rb
|
|
197
|
+
- lib/devise_remote.rb
|
|
198
|
+
- lib/devise_remote/engine.rb
|
|
199
|
+
- lib/devise_remote/http_header_authenticatable_behavior.rb
|
|
200
|
+
- lib/devise_remote/version.rb
|
|
201
|
+
- lib/generators/devise_remote/install_generator.rb
|
|
202
|
+
- lib/generators/devise_remote/login_migration_generator.rb
|
|
203
|
+
- lib/generators/devise_remote/templates/add_login_template.erb
|
|
204
|
+
- lib/generators/devise_remote/templates/devise_remote.erb
|
|
205
|
+
homepage: https://github.com/psu-libraries/devise_remote
|
|
206
|
+
licenses:
|
|
207
|
+
- Apache-2.0
|
|
208
|
+
metadata: {}
|
|
209
|
+
post_install_message:
|
|
210
|
+
rdoc_options: []
|
|
211
|
+
require_paths:
|
|
212
|
+
- lib
|
|
213
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
|
+
requirements:
|
|
215
|
+
- - ">="
|
|
216
|
+
- !ruby/object:Gem::Version
|
|
217
|
+
version: '0'
|
|
218
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
|
+
requirements:
|
|
220
|
+
- - ">="
|
|
221
|
+
- !ruby/object:Gem::Version
|
|
222
|
+
version: '0'
|
|
223
|
+
requirements: []
|
|
224
|
+
rubyforge_project:
|
|
225
|
+
rubygems_version: 2.7.4
|
|
226
|
+
signing_key:
|
|
227
|
+
specification_version: 4
|
|
228
|
+
summary: Authentication using Devise with remote services such as LDAP and Shibboleth
|
|
229
|
+
test_files: []
|