devise_g5_authenticatable 0.3.0 → 1.0.0.pre.1
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 +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +29 -7
- data/Appraisals +21 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +11 -7
- data/README.md +6 -6
- data/Rakefile +6 -5
- data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +3 -0
- data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +9 -5
- data/config/initializers/devise_g5_authenticatable.rb +2 -0
- data/devise_g5_authenticatable.gemspec +6 -5
- data/gemfiles/rails_4.1.gemfile +26 -0
- data/gemfiles/rails_4.2.gemfile +26 -0
- data/gemfiles/rails_5.0.gemfile +26 -0
- data/gemfiles/rails_5.1.gemfile +26 -0
- data/lib/devise_g5_authenticatable/controllers/helpers.rb +5 -0
- data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +3 -0
- data/lib/devise_g5_authenticatable/engine.rb +4 -1
- data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +6 -1
- data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +16 -15
- data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +11 -5
- data/lib/devise_g5_authenticatable/g5/user_exporter.rb +11 -6
- data/lib/devise_g5_authenticatable/g5.rb +2 -0
- data/lib/devise_g5_authenticatable/hooks/g5_authenticatable.rb +8 -3
- data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +38 -26
- data/lib/devise_g5_authenticatable/models/protected_attributes.rb +11 -2
- data/lib/devise_g5_authenticatable/omniauth.rb +8 -2
- data/lib/devise_g5_authenticatable/routes.rb +48 -35
- data/lib/devise_g5_authenticatable/version.rb +3 -1
- data/lib/devise_g5_authenticatable.rb +4 -1
- data/spec/controllers/helpers_spec.rb +54 -49
- data/spec/controllers/sessions_controller_spec.rb +67 -39
- data/spec/controllers/url_helpers_spec.rb +78 -78
- data/spec/dummy/app/views/{anonymous → devise}/new.html.erb +0 -0
- data/spec/dummy/config/environments/test.rb +20 -4
- data/spec/dummy/config/initializers/devise.rb +5 -1
- data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
- data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +3 -1
- data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +3 -1
- data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +3 -1
- data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +3 -1
- data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +3 -1
- data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +3 -1
- data/spec/dummy/db/schema.rb +29 -29
- data/spec/factories/admin.rb +2 -0
- data/spec/factories/user.rb +2 -0
- data/spec/features/edit_registration_spec.rb +22 -13
- data/spec/features/registration_spec.rb +13 -8
- data/spec/features/sign_in_spec.rb +4 -2
- data/spec/features/sign_out_spec.rb +4 -2
- data/spec/features/token_validation_spec.rb +24 -14
- data/spec/g5/auth_password_validator_spec.rb +28 -15
- data/spec/g5/auth_user_creator_spec.rb +29 -22
- data/spec/g5/auth_user_updater_spec.rb +23 -16
- data/spec/g5/user_exporter_spec.rb +36 -31
- data/spec/models/g5_authenticatable_spec.rb +78 -38
- data/spec/models/protected_attributes_spec.rb +24 -19
- data/spec/rails_helper.rb +46 -0
- data/spec/routing/registrations_routing_spec.rb +43 -27
- data/spec/routing/sessions_routing_spec.rb +46 -29
- data/spec/spec_helper.rb +93 -27
- data/spec/support/controller_test_helpers.rb +15 -0
- data/spec/support/devise.rb +9 -1
- data/spec/support/shared_contexts/custom_router.rb +16 -0
- data/spec/support/shared_contexts/oauth_error.rb +4 -2
- data/spec/support/shared_contexts/rake.rb +10 -4
- data/spec/support/shared_examples/registration_error.rb +3 -1
- data/spec/support/{user_feature_methods.rb → user_omniauth_methods.rb} +9 -5
- data/spec/tasks/export_users_spec.rb +5 -3
- metadata +30 -26
- data/circle.yml +0 -4
- data/spec/support/omniauth.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a11e733f9faf284c0658f3db8ddc5274801adc24
|
4
|
+
data.tar.gz: 1f581b95a86073de698cf08447006fd64799b05d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 026e2a728bf15e6903536c7c81f4470a3fe224a2f357b64b496b1dd3776b73d5adcec266275eced538552913430259b46c3f41ebc2ab2d8dd726c1bd67645e84
|
7
|
+
data.tar.gz: 47e3a3d42727b2333b2b0260baee1bfeab0c02e6a8c83b3a653636f5f7657ad9cd6d9b8cb6e97e5f3339e8d5af462dd54756c4b574d05b10a413c32a4aeff0fa
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.4
|
data/.travis.yml
CHANGED
@@ -1,13 +1,35 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache:
|
3
|
+
bundler: true
|
2
4
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
5
|
+
- 2.2.7
|
6
|
+
- 2.3.4
|
7
|
+
- 2.4.1
|
8
|
+
gemfile:
|
9
|
+
- gemfiles/rails_4.1.gemfile
|
10
|
+
- gemfiles/rails_4.2.gemfile
|
11
|
+
- gemfiles/rails_5.0.gemfile
|
12
|
+
- gemfiles/rails_5.1.gemfile
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
- rvm: 2.4.1
|
16
|
+
gemfile: gemfiles/rails_4.1.gemfile
|
17
|
+
allow_failures:
|
18
|
+
- rvm: 2.4.1
|
19
|
+
dist: trusty
|
20
|
+
sudo: false
|
21
|
+
cache:
|
22
|
+
bundler: true
|
6
23
|
before_install:
|
7
24
|
- gem update bundler
|
8
|
-
script:
|
9
|
-
- RAILS_ENV=test bundle exec rake app:db:setup
|
10
|
-
- bundle exec rspec spec
|
11
25
|
before_script:
|
12
26
|
- cp spec/dummy/config/database.yml.ci spec/dummy/config/database.yml
|
13
|
-
-
|
27
|
+
- RAILS_ENV=test bundle exec rake app:db:create app:db:migrate
|
28
|
+
script:
|
29
|
+
- bundle exec rspec
|
30
|
+
after_script:
|
31
|
+
- bundle exec codeclimate-test-reporter
|
32
|
+
addons:
|
33
|
+
code_climate:
|
34
|
+
repo_token:
|
35
|
+
secure: "jbxU8cHiS9V0vEndXRhMmteIYSyy2oq/V6S0HEqezA5nrAAnOPcLHaVhEM2Ji81G5V/k/Wda3xJ+4mXG2VU71RWCpMkWuB4M/KzAozmvxUxM7YwSfZvdYDL4AsWO+2Nvz7jDLiSTYYLigSAF5tQiD8Q6/KywcBJsXTuC5b9PTgg="
|
data/Appraisals
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise 'rails-4.1' do
|
4
|
+
gem 'protected_attributes'
|
5
|
+
gem 'rails', '~> 4.1.16'
|
6
|
+
end
|
7
|
+
|
8
|
+
appraise 'rails-4.2' do
|
9
|
+
gem 'protected_attributes'
|
10
|
+
gem 'rails', '~> 4.2.8'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'rails-5.0' do
|
14
|
+
gem 'rails', '~> 5.0.3'
|
15
|
+
gem 'rails-controller-testing', group: :test
|
16
|
+
end
|
17
|
+
|
18
|
+
appraise 'rails-5.1' do
|
19
|
+
gem 'rails', '~> 5.1.1'
|
20
|
+
gem 'rails-controller-testing', group: :test
|
21
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## v1.0.0.pre.1 (TBD)
|
2
|
+
|
3
|
+
* **Backwards incompatible changes**
|
4
|
+
* Dropped support for rails < 4.1
|
5
|
+
* Dropped support for ruby < 2.2 (older versions *may* continue to work for
|
6
|
+
now, but there are no guarantees)
|
7
|
+
* Dropped support for devise < 4.3. The breaking change most likely to affect
|
8
|
+
users of this gem is the removal of omniauth route helpers with a wildcard
|
9
|
+
`:provider` parameter. However, the other forms of omniauth route helpers
|
10
|
+
still work. For example, `user_omniauth_authorize_path(:g5)` is no longer
|
11
|
+
valid, but you can still use `user_g5_omniauth_authorize_path` (preferred)
|
12
|
+
or `omniauth_authorize_path(:user, :g5)`
|
13
|
+
* Enhancements
|
14
|
+
* Added support for ruby 2.3 and 2.4
|
15
|
+
* Added support for rails 5.0 and 5.1
|
16
|
+
* Bug fixes
|
17
|
+
* The devise upgrade picked up a number of bug fixes, most notably the
|
18
|
+
`FailureApp` nil `script_name` issue introduced in devise 3.5.2, which broke
|
19
|
+
route generation within mounted engines (see
|
20
|
+
[plataformatec/devise#3705](https://github.com/plataformatec/devise/issues/3705))
|
21
|
+
|
1
22
|
## v0.3.0 (2016-11-03)
|
2
23
|
|
3
24
|
* Exposes callbacks for more fine-grained control over mapping auth user
|
@@ -5,12 +26,15 @@
|
|
5
26
|
([#25](https://github.com/G5/devise_g5_authenticatable/pull/25))
|
6
27
|
|
7
28
|
## v0.2.4 (2015-12-09)
|
29
|
+
|
8
30
|
* Same as v0.2.4.beta but not is a stable version!
|
9
31
|
|
10
32
|
## v0.2.4.beta (2015-12-03)
|
33
|
+
|
11
34
|
* Enforces uniqueness of email address in when looking for an email without UID
|
12
35
|
|
13
36
|
## v0.2.3 (2015-11-30)
|
37
|
+
|
14
38
|
* Pins version of devise to 3.5.1 due - https://github.com/plataformatec/devise/issues/3705
|
15
39
|
* Pins version of omniauth-g5 to v0.3.1 due - https://github.com/G5/omniauth-g5/pull/10
|
16
40
|
|
data/Gemfile
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in devise_g5_authenticatable.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
8
|
# Dependencies for the dummy test app
|
7
|
-
gem 'rails', '4.1.4'
|
8
9
|
gem 'jquery-rails'
|
9
10
|
gem 'pg'
|
10
|
-
|
11
|
+
|
12
|
+
# See the Appraisals file for all supported rails versions
|
13
|
+
gem 'rails', '~> 5.1.1'
|
11
14
|
|
12
15
|
group :test, :development do
|
13
|
-
gem '
|
14
|
-
gem 'rspec-activemodel-mocks'
|
16
|
+
gem 'appraisal'
|
15
17
|
gem 'pry-byebug'
|
18
|
+
gem 'rspec-rails', '~> 3.6'
|
16
19
|
end
|
17
20
|
|
18
21
|
group :test do
|
19
22
|
gem 'capybara'
|
23
|
+
gem 'codeclimate-test-reporter', '~> 1.0'
|
24
|
+
gem 'factory_girl_rails', '~> 4.8', require: false
|
25
|
+
gem 'rspec-activemodel-mocks'
|
26
|
+
gem 'shoulda-matchers', '~> 3.1'
|
20
27
|
gem 'simplecov'
|
21
|
-
gem 'codeclimate-test-reporter'
|
22
28
|
gem 'webmock'
|
23
|
-
gem 'shoulda-matchers', '~> 2.6'
|
24
|
-
gem 'factory_girl_rails', '~> 4.3', require: false
|
25
29
|
end
|
data/README.md
CHANGED
@@ -10,13 +10,13 @@ G5 users.
|
|
10
10
|
|
11
11
|
## Current Version
|
12
12
|
|
13
|
-
0.
|
13
|
+
1.0.0.pre.1
|
14
14
|
|
15
15
|
## Requirements
|
16
16
|
|
17
|
-
* [Ruby](https://github.com/ruby/ruby) >= 2.
|
18
|
-
* [Rails](https://github.com/rails/rails) >=
|
19
|
-
* [Devise](https://github.com/plataformatec/devise) ~> 3
|
17
|
+
* [Ruby](https://github.com/ruby/ruby) >= 2.2
|
18
|
+
* [Rails](https://github.com/rails/rails) >= 4.1
|
19
|
+
* [Devise](https://github.com/plataformatec/devise) ~> 4.3
|
20
20
|
|
21
21
|
## Installation
|
22
22
|
|
@@ -90,10 +90,10 @@ end
|
|
90
90
|
### Controller filters and helpers
|
91
91
|
|
92
92
|
To require authentication for a controller, use one of devise's generated
|
93
|
-
|
93
|
+
before_actions. For example:
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
|
96
|
+
before_action :authenticate_user!
|
97
97
|
```
|
98
98
|
|
99
99
|
All of [devise's controller helpers](https://github.com/plataformatec/devise#controller-filters-and-helpers)
|
data/Rakefile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
begin
|
3
4
|
require 'bundler/setup'
|
4
5
|
rescue LoadError
|
5
6
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
7
|
end
|
7
8
|
|
8
|
-
APP_RAKEFILE = File.expand_path(
|
9
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
9
10
|
load 'rails/tasks/engine.rake'
|
10
11
|
|
11
12
|
Bundler::GemHelper.install_tasks
|
@@ -15,6 +16,6 @@ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
|
|
15
16
|
require 'rspec/core'
|
16
17
|
require 'rspec/core/rake_task'
|
17
18
|
|
18
|
-
desc
|
19
|
-
RSpec::Core::RakeTask.new(:
|
20
|
-
task :
|
19
|
+
desc 'Run all specs in spec directory (excluding plugin specs)'
|
20
|
+
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
|
21
|
+
task default: :spec
|
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeviseG5Authenticatable
|
4
|
+
# Custom sessions controller to require sign-in through the G5 auth server
|
2
5
|
class SessionsController < Devise::OmniauthCallbacksController
|
3
|
-
|
6
|
+
prepend_before_action :require_no_authentication, only: %i[new create]
|
4
7
|
|
5
8
|
def new
|
6
9
|
redirect_to g5_authorize_path(resource_name)
|
7
10
|
end
|
8
11
|
|
9
12
|
def omniauth_passthru
|
10
|
-
render status: 404,
|
13
|
+
render status: 404, plain: 'Authentication passthru.'
|
11
14
|
end
|
12
15
|
|
13
16
|
def create
|
@@ -22,6 +25,7 @@ module DeviseG5Authenticatable
|
|
22
25
|
end
|
23
26
|
|
24
27
|
protected
|
28
|
+
|
25
29
|
def auth_data
|
26
30
|
@auth_data ||= request.env['omniauth.auth']
|
27
31
|
session['omniauth.auth'] = @auth_data
|
@@ -42,8 +46,8 @@ module DeviseG5Authenticatable
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def remote_sign_out
|
45
|
-
redirect_url =
|
46
|
-
|
49
|
+
redirect_url = URI.join(request.base_url,
|
50
|
+
after_sign_out_path_for(resource_name))
|
47
51
|
redirect_to auth_client.sign_out_url(redirect_url.to_s)
|
48
52
|
end
|
49
53
|
|
@@ -51,7 +55,7 @@ module DeviseG5Authenticatable
|
|
51
55
|
G5AuthenticationClient::Client.new
|
52
56
|
end
|
53
57
|
|
54
|
-
def after_omniauth_failure_path_for(
|
58
|
+
def after_omniauth_failure_path_for(_scope)
|
55
59
|
main_app.root_path
|
56
60
|
end
|
57
61
|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'devise_g5_authenticatable/version'
|
@@ -6,6 +8,7 @@ require 'devise_g5_authenticatable/version'
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
9
|
spec.name = 'devise_g5_authenticatable'
|
8
10
|
spec.version = DeviseG5Authenticatable::VERSION
|
11
|
+
spec.platform = Gem::Platform::RUBY
|
9
12
|
spec.authors = ['Maeve Revels']
|
10
13
|
spec.email = ['maeve.revels@getg5.com']
|
11
14
|
spec.description = 'Devise extension for the G5 Auth service'
|
@@ -13,15 +16,13 @@ Gem::Specification.new do |spec|
|
|
13
16
|
spec.homepage = 'https://github.com/G5/devise_g5_authenticatable'
|
14
17
|
spec.license = 'MIT'
|
15
18
|
|
16
|
-
spec.files = `git ls-files`.split(
|
19
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
22
|
spec.require_paths = ['lib']
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
spec.add_dependency 'devise', '= 3.5.1'
|
24
|
-
spec.add_dependency 'g5_authentication_client', '~> 0.5', '>= 0.5.4'
|
24
|
+
spec.add_dependency 'devise', '~> 4.3'
|
25
|
+
spec.add_dependency 'g5_authentication_client', '1.0.0.pre.4'
|
25
26
|
|
26
27
|
# Pinned to version 0.3.1 due https://github.com/G5/omniauth-g5/pull/10
|
27
28
|
# Omniauth-auth2 removed 'callback_url' which broke our auth workflow
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "jquery-rails"
|
6
|
+
gem "pg"
|
7
|
+
gem "rails", "~> 4.1.16"
|
8
|
+
gem "protected_attributes"
|
9
|
+
|
10
|
+
group :test, :development do
|
11
|
+
gem "appraisal"
|
12
|
+
gem "pry-byebug"
|
13
|
+
gem "rspec-rails", "~> 3.6"
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "capybara"
|
18
|
+
gem "codeclimate-test-reporter", "~> 1.0"
|
19
|
+
gem "factory_girl_rails", "~> 4.8", require: false
|
20
|
+
gem "rspec-activemodel-mocks"
|
21
|
+
gem "shoulda-matchers", "~> 3.1"
|
22
|
+
gem "simplecov"
|
23
|
+
gem "webmock"
|
24
|
+
end
|
25
|
+
|
26
|
+
gemspec path: "../"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "jquery-rails"
|
6
|
+
gem "pg"
|
7
|
+
gem "rails", "~> 4.2.8"
|
8
|
+
gem "protected_attributes"
|
9
|
+
|
10
|
+
group :test, :development do
|
11
|
+
gem "appraisal"
|
12
|
+
gem "pry-byebug"
|
13
|
+
gem "rspec-rails", "~> 3.6"
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "capybara"
|
18
|
+
gem "codeclimate-test-reporter", "~> 1.0"
|
19
|
+
gem "factory_girl_rails", "~> 4.8", require: false
|
20
|
+
gem "rspec-activemodel-mocks"
|
21
|
+
gem "shoulda-matchers", "~> 3.1"
|
22
|
+
gem "simplecov"
|
23
|
+
gem "webmock"
|
24
|
+
end
|
25
|
+
|
26
|
+
gemspec path: "../"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "jquery-rails"
|
6
|
+
gem "pg"
|
7
|
+
gem "rails", "~> 5.0.3"
|
8
|
+
gem "rails-controller-testing", group: :test
|
9
|
+
|
10
|
+
group :test, :development do
|
11
|
+
gem "appraisal"
|
12
|
+
gem "pry-byebug"
|
13
|
+
gem "rspec-rails", "~> 3.6"
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "capybara"
|
18
|
+
gem "codeclimate-test-reporter", "~> 1.0"
|
19
|
+
gem "factory_girl_rails", "~> 4.8", require: false
|
20
|
+
gem "rspec-activemodel-mocks"
|
21
|
+
gem "shoulda-matchers", "~> 3.1"
|
22
|
+
gem "simplecov"
|
23
|
+
gem "webmock"
|
24
|
+
end
|
25
|
+
|
26
|
+
gemspec path: "../"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "jquery-rails"
|
6
|
+
gem "pg"
|
7
|
+
gem "rails", "~> 5.1.1"
|
8
|
+
gem "rails-controller-testing", group: :test
|
9
|
+
|
10
|
+
group :test, :development do
|
11
|
+
gem "appraisal"
|
12
|
+
gem "pry-byebug"
|
13
|
+
gem "rspec-rails", "~> 3.6"
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "capybara"
|
18
|
+
gem "codeclimate-test-reporter", "~> 1.0"
|
19
|
+
gem "factory_girl_rails", "~> 4.8", require: false
|
20
|
+
gem "rspec-activemodel-mocks"
|
21
|
+
gem "shoulda-matchers", "~> 3.1"
|
22
|
+
gem "simplecov"
|
23
|
+
gem "webmock"
|
24
|
+
end
|
25
|
+
|
26
|
+
gemspec path: "../"
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeviseG5Authenticatable
|
4
|
+
# Utility helper methods to mixin to controllers
|
2
5
|
module Helpers
|
3
6
|
extend ActiveSupport::Concern
|
4
7
|
|
@@ -23,6 +26,8 @@ module DeviseG5Authenticatable
|
|
23
26
|
respond_with(resource)
|
24
27
|
end
|
25
28
|
|
29
|
+
# Dynamically generate helper methods with devise resource name
|
30
|
+
# e.g. `set_updated_by_user` or `set_updated_by_admin`
|
26
31
|
module ClassMethods
|
27
32
|
def define_helpers(mapping)
|
28
33
|
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeviseG5Authenticatable
|
4
|
+
# The main class for initializing the rails engine
|
2
5
|
class Engine < Rails::Engine
|
3
|
-
initializer
|
6
|
+
initializer 'devise_g5_authenticatable.helpers' do
|
4
7
|
Devise.include_helpers(DeviseG5Authenticatable)
|
5
8
|
end
|
6
9
|
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'g5_authentication_client'
|
2
4
|
|
3
5
|
module Devise
|
4
6
|
module G5
|
7
|
+
# Validate a user's G5 Auth credentials
|
5
8
|
class AuthPasswordValidator
|
6
9
|
attr_reader :model
|
7
10
|
|
@@ -22,8 +25,10 @@ module Devise
|
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
28
|
+
|
25
29
|
def auth_client(password)
|
26
|
-
G5AuthenticationClient::Client.new(username: model.email,
|
30
|
+
G5AuthenticationClient::Client.new(username: model.email,
|
31
|
+
password: password)
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'g5_authentication_client'
|
2
4
|
|
3
5
|
module Devise
|
4
6
|
module G5
|
7
|
+
# Create a new user account on the G5 Auth server
|
5
8
|
class AuthUserCreator
|
6
9
|
attr_reader :model
|
7
10
|
|
@@ -14,20 +17,16 @@ module Devise
|
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
20
|
+
|
17
21
|
def create_auth_user
|
18
|
-
|
22
|
+
update_auth_attributes(auth_user)
|
19
23
|
end
|
20
24
|
|
21
25
|
def auth_user
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
existing_auth_user
|
27
|
-
else
|
28
|
-
raise e
|
29
|
-
end
|
30
|
-
end
|
26
|
+
auth_client.create_user(auth_user_args)
|
27
|
+
rescue StandardError => error
|
28
|
+
raise error unless error.message =~ /Email has already been taken/
|
29
|
+
existing_auth_user
|
31
30
|
end
|
32
31
|
|
33
32
|
def existing_auth_user
|
@@ -43,7 +42,9 @@ module Devise
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def auth_client
|
46
|
-
G5AuthenticationClient::Client.new(
|
45
|
+
G5AuthenticationClient::Client.new(
|
46
|
+
access_token: updated_by.g5_access_token
|
47
|
+
)
|
47
48
|
end
|
48
49
|
|
49
50
|
def updated_by
|
@@ -51,12 +52,12 @@ module Devise
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def auth_user_args
|
54
|
-
{email: model.email,
|
55
|
-
|
56
|
-
|
55
|
+
{ email: model.email,
|
56
|
+
password: model.password,
|
57
|
+
password_confirmation: model.password_confirmation }
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
+
def update_auth_attributes(auth_user)
|
60
61
|
model.provider = 'g5'
|
61
62
|
model.uid = auth_user.id
|
62
63
|
model.clean_up_passwords
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'g5_authentication_client'
|
2
4
|
|
3
5
|
module Devise
|
4
6
|
module G5
|
7
|
+
# Update user data on G5 Auth server
|
5
8
|
class AuthUserUpdater
|
6
9
|
attr_reader :model
|
7
10
|
|
@@ -14,6 +17,7 @@ module Devise
|
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
20
|
+
|
17
21
|
def update_auth_user
|
18
22
|
auth_user = auth_client.update_user(auth_user_args)
|
19
23
|
model.clean_up_passwords
|
@@ -25,7 +29,9 @@ module Devise
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def auth_client
|
28
|
-
G5AuthenticationClient::Client.new(
|
32
|
+
G5AuthenticationClient::Client.new(
|
33
|
+
access_token: updated_by.g5_access_token
|
34
|
+
)
|
29
35
|
end
|
30
36
|
|
31
37
|
def updated_by
|
@@ -33,10 +39,10 @@ module Devise
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def auth_user_args
|
36
|
-
{id: model.uid,
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
{ id: model.uid,
|
43
|
+
email: model.email,
|
44
|
+
password: model.password,
|
45
|
+
password_confirmation: model.password_confirmation }
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'g5_authentication_client'
|
2
4
|
|
3
5
|
module G5
|
@@ -11,7 +13,7 @@ module G5
|
|
11
13
|
# @option options [String] :redirect_uri the redirect URI registered with G5
|
12
14
|
# @option options [String] :endpoint the endpoint for the G5 Auth server
|
13
15
|
# @option options [String] :authorization_code the G5 authorization code to obtain an access token
|
14
|
-
def initialize(options={})
|
16
|
+
def initialize(options = {})
|
15
17
|
@client_id = options[:client_id]
|
16
18
|
@client_secret = options[:client_secret]
|
17
19
|
@redirect_uri = options[:redirect_uri]
|
@@ -40,6 +42,7 @@ module G5
|
|
40
42
|
end
|
41
43
|
|
42
44
|
private
|
45
|
+
|
43
46
|
def update_local_user(local_user, auth_user)
|
44
47
|
local_user.uid = auth_user.id
|
45
48
|
local_user.provider = 'g5'
|
@@ -51,11 +54,13 @@ module G5
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def auth_client
|
54
|
-
@oauth_client ||= G5AuthenticationClient::Client.new(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
@oauth_client ||= G5AuthenticationClient::Client.new(
|
58
|
+
client_id: @client_id,
|
59
|
+
client_secret: @client_secret,
|
60
|
+
redirect_uri: @redirect_uri,
|
61
|
+
endpoint: @endpoint,
|
62
|
+
authorization_code: @authorization_code
|
63
|
+
)
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|