devise_g5_authenticatable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +23 -0
- data/LICENSE +20 -0
- data/README.md +243 -0
- data/Rakefile +20 -0
- data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +5 -0
- data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +58 -0
- data/circle.yml +4 -0
- data/config/initializers/devise_g5_authenticatable.rb +3 -0
- data/config/locales/en.yml +6 -0
- data/devise_g5_authenticatable.gemspec +24 -0
- data/lib/devise_g5_authenticatable.rb +16 -0
- data/lib/devise_g5_authenticatable/controllers/helpers.rb +37 -0
- data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +13 -0
- data/lib/devise_g5_authenticatable/engine.rb +11 -0
- data/lib/devise_g5_authenticatable/g5.rb +4 -0
- data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +30 -0
- data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +48 -0
- data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +43 -0
- data/lib/devise_g5_authenticatable/g5/user_exporter.rb +61 -0
- data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +99 -0
- data/lib/devise_g5_authenticatable/models/protected_attributes.rb +16 -0
- data/lib/devise_g5_authenticatable/omniauth.rb +9 -0
- data/lib/devise_g5_authenticatable/routes.rb +58 -0
- data/lib/devise_g5_authenticatable/version.rb +3 -0
- data/lib/tasks/g5/export_users.rake +13 -0
- data/spec/controllers/helpers_spec.rb +295 -0
- data/spec/controllers/sessions_controller_spec.rb +256 -0
- data/spec/controllers/url_helpers_spec.rb +332 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/custom_sessions.js +2 -0
- data/spec/dummy/app/assets/javascripts/home.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/custom_sessions.css +4 -0
- data/spec/dummy/app/assets/stylesheets/home.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/custom_registrations_controllers.rb +2 -0
- data/spec/dummy/app/controllers/custom_sessions_controller.rb +2 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/custom_sessions_helper.rb +2 -0
- data/spec/dummy/app/helpers/home_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/admin.rb +3 -0
- data/spec/dummy/app/models/user.rb +10 -0
- data/spec/dummy/app/views/anonymous/new.html.erb +0 -0
- data/spec/dummy/app/views/home/index.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +64 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml.ci +6 -0
- data/spec/dummy/config/database.yml.sample +13 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +39 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +259 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +60 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +70 -0
- data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +16 -0
- data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +16 -0
- data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +13 -0
- data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +18 -0
- data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +8 -0
- data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +42 -0
- data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +8 -0
- data/spec/dummy/db/schema.rb +50 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/factories/admin.rb +10 -0
- data/spec/factories/user.rb +10 -0
- data/spec/features/edit_registration_spec.rb +109 -0
- data/spec/features/registration_spec.rb +99 -0
- data/spec/features/sign_in_spec.rb +91 -0
- data/spec/features/sign_out_spec.rb +7 -0
- data/spec/g5/auth_password_validator_spec.rb +81 -0
- data/spec/g5/auth_user_creator_spec.rb +100 -0
- data/spec/g5/auth_user_updater_spec.rb +113 -0
- data/spec/g5/user_exporter_spec.rb +105 -0
- data/spec/models/g5_authenticatable_spec.rb +540 -0
- data/spec/models/protected_attributes_spec.rb +17 -0
- data/spec/routing/registrations_routing_spec.rb +107 -0
- data/spec/routing/sessions_routing_spec.rb +111 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/devise.rb +3 -0
- data/spec/support/omniauth.rb +3 -0
- data/spec/support/shared_contexts/oauth_error.rb +9 -0
- data/spec/support/shared_contexts/rake.rb +21 -0
- data/spec/support/shared_examples/registration_error.rb +15 -0
- data/spec/support/user_feature_methods.rb +26 -0
- data/spec/tasks/export_users_spec.rb +90 -0
- metadata +293 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e6178bfffa50bb6940208406f65192bc3fa8e8e
|
4
|
+
data.tar.gz: 36ae13c7b26dfc6af43a26cb6c22f36e0c93e2a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd3303525818dea3add1c492fd6dc45500240fb308d1f098dae9966601735bb730ddb93f646cef8c9bdcaf35f31b8d878d2a288074fd8a5925a68b52bf772713
|
7
|
+
data.tar.gz: 4656dcac40c6697ab9bc249660848bd207b5a8f948c85b1ba3b9c6f2c8ec89ae312e604eec5f5dd86e15515820fb00d70d131d39f1332019173e7d7cbdb83ae0
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
.DS_Store
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
coverage
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
lib/bundler/man
|
10
|
+
pkg
|
11
|
+
rdoc
|
12
|
+
spec/reports
|
13
|
+
test/tmp
|
14
|
+
test/version_tmp
|
15
|
+
tmp
|
16
|
+
spec/dummy/config/database.yml
|
17
|
+
|
18
|
+
# YARD artifacts
|
19
|
+
.yardoc
|
20
|
+
_yardoc
|
21
|
+
doc/
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## v0.1.0 (2014-03-12)
|
2
|
+
|
3
|
+
* Move `rake g5:export_users` from
|
4
|
+
[omniauth-g5](https://github.com/g5search/omniauth-g5)
|
5
|
+
* First open source release to [RubyGems](https://rubygems.org)
|
6
|
+
|
7
|
+
## v0.0.4 (2014-02-26)
|
8
|
+
|
9
|
+
* Use the main app's root path (necessary when mounted inside another Rails
|
10
|
+
engine with `isolate_namespace`)
|
11
|
+
|
12
|
+
## v0.0.3 (2014-02-10)
|
13
|
+
|
14
|
+
* Bug fix: fix type conversion errors against PostgreSQL. Assume that model
|
15
|
+
`provider` and `uid` are stored as strings.
|
16
|
+
|
17
|
+
## v0.0.2 (2014-02-05)
|
18
|
+
|
19
|
+
* Bug fix: conditionally require model-level mass assignment logic
|
20
|
+
(e.g. `attr_accessible`) so that the gem can be used in either Rails 3.2 or
|
21
|
+
Rails 4.
|
22
|
+
|
23
|
+
## v0.0.1 (2014-02-04)
|
24
|
+
|
25
|
+
* Initial release
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in devise_g5_authenticatable.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# Dependencies for the dummy test app
|
7
|
+
gem 'rails', '~> 3.2.15'
|
8
|
+
gem 'jquery-rails'
|
9
|
+
gem 'pg'
|
10
|
+
|
11
|
+
group :test, :development do
|
12
|
+
gem 'rspec-rails', '~> 2.14'
|
13
|
+
gem 'pry'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'capybara'
|
18
|
+
gem 'simplecov'
|
19
|
+
gem 'codeclimate-test-reporter'
|
20
|
+
gem 'webmock'
|
21
|
+
gem 'shoulda-matchers'
|
22
|
+
gem 'factory_girl_rails', '~> 4.3', require: false
|
23
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 G5
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
# Devise G5 Authenticatable
|
2
|
+
|
3
|
+
Devise G5 Authenticatable extends devise to provide an
|
4
|
+
[OAuth 2.0](http://oauth.net/2)-based authentication strategy and remote
|
5
|
+
credential management via the G5 Auth service.
|
6
|
+
|
7
|
+
Devise G5 Authenticatable is intended as a drop-in replacement for the
|
8
|
+
Database Authenticatable module, in order to support single sign-on for
|
9
|
+
G5 users.
|
10
|
+
|
11
|
+
## Current Version
|
12
|
+
|
13
|
+
0.1.0
|
14
|
+
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
* [Ruby](https://github.com/ruby/ruby) >= 1.9.3
|
18
|
+
* [Rails](https://github.com/rails/rails) >= 3.2
|
19
|
+
* [Devise](https://github.com/plataformatec/devise) ~> 3.0
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
gem 'devise_g5_authenticatable'
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install devise_g5_authenticatable
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### Registering your OAuth application
|
38
|
+
|
39
|
+
1. Visit the [auth server admin console](https://auth.g5search.com/admin)
|
40
|
+
and login.
|
41
|
+
2. Click "New Application"
|
42
|
+
3. Enter a name that recognizably identifies your application.
|
43
|
+
4. Enter the redirect URI where the auth server should redirect
|
44
|
+
after the user successfully authenticates. It will generally be
|
45
|
+
of the form `http://<apphost>/<devise_path>/auth/g5/callback`.
|
46
|
+
|
47
|
+
For non-production environments, this redirect URI does not have to
|
48
|
+
be publicly accessible, but it must be accessible from the browser
|
49
|
+
where you will be testing (so using something like
|
50
|
+
http://localhost:3000/users/auth/g5/callback is fine if your browser
|
51
|
+
and client application server are both local).
|
52
|
+
5. For a trusted G5 application, check the "Auto-authorize?" checkbox. This
|
53
|
+
skips the OAuth authorization step where the user is prompted to explicitly
|
54
|
+
authorize the client application to access the user's data.
|
55
|
+
6. Click "Submit" to obtain the client application's credentials.
|
56
|
+
|
57
|
+
### Environment variables
|
58
|
+
|
59
|
+
Once you have your OAuth 2.0 credentials, you'll need to set the following
|
60
|
+
environment variables for your client application:
|
61
|
+
|
62
|
+
* `G5_AUTH_CLIENT_ID` - the OAuth 2.0 application ID from the auth server
|
63
|
+
* `G5_AUTH_CLIENT_SECRET` - the OAuth 2.0 application secret from the auth server
|
64
|
+
* `G5_AUTH_REDIRECT_URI` - the OAuth 2.0 redirect URI registered with the auth server
|
65
|
+
* `G5_AUTH_ENDPOINT` - the endpoint URL for the G5 auth server
|
66
|
+
|
67
|
+
### Configuration
|
68
|
+
|
69
|
+
In `config/initializers/devise.rb`, add the following:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Devise.setup do |config|
|
73
|
+
# ...
|
74
|
+
config.omniauth :g5, ENV['G5_AUTH_CLIENT_ID'], ENV['G5_AUTH_CLIENT_SECRET'],
|
75
|
+
client_options: {site: ENV['G5_AUTH_ENDPOINT']}
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Create `config/initializers/g5_auth.rb` with the following:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
G5AuthenticationClient.configure do |defaults|
|
83
|
+
defaults.client_id = ENV['G5_AUTH_CLIENT_ID']
|
84
|
+
defaults.client_secret = ENV['G5_AUTH_CLIENT_SECRET']
|
85
|
+
defaults.redirect_uri = ENV['G5_AUTH_REDIRECT_URI']
|
86
|
+
defaults.endpoint = ENV['G5_AUTH_ENDPOINT']
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
### Controller filters and helpers
|
91
|
+
|
92
|
+
To require authentication for a controller, use one of devise's generated
|
93
|
+
before_filters. For example:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
before_filter :authenticate_user!
|
97
|
+
```
|
98
|
+
|
99
|
+
All of [devise's controller helpers](https://github.com/plataformatec/devise#controller-filters-and-helpers)
|
100
|
+
are available inside a controller. To access the model for the signed-in user:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
current_user
|
104
|
+
```
|
105
|
+
|
106
|
+
To check if there is a user signed in:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
user_signed_in?
|
110
|
+
```
|
111
|
+
|
112
|
+
To access the scoped session:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
user_session
|
116
|
+
```
|
117
|
+
|
118
|
+
### Route helpers
|
119
|
+
|
120
|
+
This gem will generate devise's usual route helpers for session management.
|
121
|
+
For example, if you have configured devise with a `:user` scope, you will have
|
122
|
+
the following helpers:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
new_user_session_path
|
126
|
+
new_session_path(:user)
|
127
|
+
|
128
|
+
destroy_user_session_path
|
129
|
+
destroy_session_path(:user)
|
130
|
+
```
|
131
|
+
|
132
|
+
The gem also provides routes for OmniAuth's integration points, although you
|
133
|
+
will rarely need to call these directly:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
user_g5_authorize_path
|
137
|
+
g5_authorize_path(:user)
|
138
|
+
|
139
|
+
user_g5_callback_path
|
140
|
+
g5_callback_path(:user)
|
141
|
+
```
|
142
|
+
|
143
|
+
### Configuring the model
|
144
|
+
|
145
|
+
In your User model (or whatever model you've configured for use with devise):
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
class User < ActiveRecord::Base
|
149
|
+
devise :g5_authenticatable # plus whatever other devise modules you'd like
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
153
|
+
### Configuring a custom controller
|
154
|
+
|
155
|
+
You can use `devise_for` to hook in a custom controller in your routes,
|
156
|
+
[the same way as devise](https://github.com/plataformatec/devise#configuring-controllers):
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
devise_for :admins, controllers: {sessions: 'admins/sessions'}
|
160
|
+
```
|
161
|
+
|
162
|
+
If you need to override the sessions controller, remember to extend the correct
|
163
|
+
base class:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
class Admins::SessionsController < DeviseG5Authenticatable::SessionsController
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
### Strong Parameters
|
171
|
+
|
172
|
+
If installed in a Rails 4 application, this gem will automatically use
|
173
|
+
[devise's parameter sanitizer](https://github.com/plataformatec/devise#strong-parameters)
|
174
|
+
logic. Under Rails 3.2.x, it will make the appropriate calls to
|
175
|
+
`attr_accessible` in the model.
|
176
|
+
|
177
|
+
If you are using Rails 4 in conjunction with the
|
178
|
+
[protected_attributes](https://github.com/rails/protected_attributes) gem, you
|
179
|
+
will need to insert the following in your `config/initializers/devise.rb`:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
require 'devise_g5_authenticatable/models/protected_attributes'
|
183
|
+
```
|
184
|
+
|
185
|
+
## Examples
|
186
|
+
|
187
|
+
Currently, the best source of example code is in the [test Rails
|
188
|
+
application](spec/dummy) used for integration testing.
|
189
|
+
|
190
|
+
## Authors
|
191
|
+
|
192
|
+
* Maeve Revels / [@maeve](https://github.com/maeve)
|
193
|
+
|
194
|
+
## Contributing
|
195
|
+
|
196
|
+
1. Fork it
|
197
|
+
2. Get it running (see Installation above)
|
198
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
199
|
+
4. Write your code and **specs**
|
200
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
201
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
202
|
+
7. Create new Pull Request
|
203
|
+
|
204
|
+
If you find bugs, have feature requests or questions, please
|
205
|
+
[file an issue](https://github.com/G5/devise_g5_authenticatable/issues).
|
206
|
+
|
207
|
+
### Specs
|
208
|
+
|
209
|
+
Before running the specs for the first time, you will need to initialize the
|
210
|
+
database for the test Rails application:
|
211
|
+
|
212
|
+
$ cp spec/dummy/config/database.yml.sample spec/dummy/config/database.yml
|
213
|
+
$ RAILS_ENV=test bundle exec rake app:db:setup
|
214
|
+
|
215
|
+
|
216
|
+
To execute the entire test suite:
|
217
|
+
|
218
|
+
$ bundle exec rspec spec
|
219
|
+
|
220
|
+
## License
|
221
|
+
|
222
|
+
Copyright (c) 2013 G5
|
223
|
+
|
224
|
+
MIT License
|
225
|
+
|
226
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
227
|
+
a copy of this software and associated documentation files (the
|
228
|
+
"Software"), to deal in the Software without restriction, including
|
229
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
230
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
231
|
+
permit persons to whom the Software is furnished to do so, subject to
|
232
|
+
the following conditions:
|
233
|
+
|
234
|
+
The above copyright notice and this permission notice shall be
|
235
|
+
included in all copies or substantial portions of the Software.
|
236
|
+
|
237
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
238
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
239
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
240
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
241
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
242
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
243
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
9
|
+
load 'rails/tasks/engine.rake'
|
10
|
+
|
11
|
+
Bundler::GemHelper.install_tasks
|
12
|
+
|
13
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
|
14
|
+
|
15
|
+
require 'rspec/core'
|
16
|
+
require 'rspec/core/rake_task'
|
17
|
+
|
18
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
19
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
20
|
+
task :default => :spec
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module DeviseG5Authenticatable
|
2
|
+
class SessionsController < Devise::OmniauthCallbacksController
|
3
|
+
prepend_before_filter :require_no_authentication, only: [:new, :create]
|
4
|
+
|
5
|
+
def new
|
6
|
+
redirect_to g5_authorize_path(resource_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def omniauth_passthru
|
10
|
+
render status: 404, text: 'Authentication passthru.'
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
self.resource = resource_class.find_and_update_for_g5_oauth(auth_data)
|
15
|
+
resource ? sign_in_resource : register_resource
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
signed_in_resource.revoke_g5_credentials!
|
20
|
+
local_sign_out
|
21
|
+
remote_sign_out
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def auth_data
|
26
|
+
@auth_data ||= request.env['omniauth.auth']
|
27
|
+
session['omniauth.auth'] = @auth_data
|
28
|
+
end
|
29
|
+
|
30
|
+
def sign_in_resource
|
31
|
+
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
32
|
+
sign_in_and_redirect(resource)
|
33
|
+
end
|
34
|
+
|
35
|
+
def register_resource
|
36
|
+
set_flash_message(:alert, :not_found) if is_navigational_format?
|
37
|
+
redirect_to(new_registration_path(resource_name))
|
38
|
+
end
|
39
|
+
|
40
|
+
def local_sign_out
|
41
|
+
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def remote_sign_out
|
45
|
+
redirect_url = URI.join(request.base_url,
|
46
|
+
after_sign_out_path_for(resource_name))
|
47
|
+
redirect_to auth_client.sign_out_url(redirect_url.to_s)
|
48
|
+
end
|
49
|
+
|
50
|
+
def auth_client
|
51
|
+
G5AuthenticationClient::Client.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def after_omniauth_failure_path_for(scope)
|
55
|
+
main_app.root_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/circle.yml
ADDED