devise_auth_proxy 0.1.14 → 0.1.19
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/Gemfile.lock +1 -1
- data/README.md +32 -8
- data/lib/devise_auth_proxy.rb +5 -2
- data/lib/devise_auth_proxy/controller.rb +17 -0
- data/lib/devise_auth_proxy/manager.rb +13 -7
- data/lib/devise_auth_proxy/model.rb +0 -4
- data/lib/devise_auth_proxy/strategy.rb +6 -2
- data/lib/devise_auth_proxy/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b729be65182611e2eea74a226c4df6b3dfdeda4f740e413cbfd412de8cf46702
|
4
|
+
data.tar.gz: 230e8bec895d53a1d353406e90f14f03d329ddf42a2f99990ae4debf9fff905a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 886b7820587d7fe3499cc5cfa9617976ac53926c1bd90639b4bcbe3e5f77444011dc9bc40c29a39bbf27c231aca79b2692444c4b334b6f78c231b9c11b91172b
|
7
|
+
data.tar.gz: 262293792ff984a618575afb8b81ae305cadbde8d1e04ef7a3d233fca0dccb84422ce1ff884d63b71a83556a2cf97db8151f29374497b9b789d65cc0d803974c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# DeviseAuthProxy
|
2
2
|
|
3
|
-
|
3
|
+
A devise extension for proxy user authentication.
|
4
4
|
|
5
|
-
|
5
|
+
[](http://badge.fury.io/rb/devise_auth_proxy)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem 'devise_auth_proxy'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -18,11 +18,35 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install
|
21
|
+
$ gem install devise_auth_proxy
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Invoke hook
|
26
|
+
* Add `:auth_proxy_authenticatable` symbol to `devise` statement in User model, before other authentication strategies (e.g., `:database_authenticatable`).
|
27
|
+
|
28
|
+
Configuaration options:
|
29
|
+
* `env_key` - String (default: 'AUTH_PROXY'). Request environment key for the proxy user id.
|
30
|
+
* `attribute_map` - Hash (default: {}). Map of User model attributes to request environment keys for updating the local user when auto-creation is enabled.
|
31
|
+
* `auto_create` - Boolean (default: false). Whether to auto-create a local user from the proxy user attributes. Note: Also requires adding the Warden callbacks as shown below.
|
32
|
+
* `auto_update` - Boolean (default: false). Whether to auto-update authenticated user attributes from proxy user attributes.
|
33
|
+
* `logout_url` - String (default: '/'). For redirecting to a proxy user logout URL after signing out of the Rails application. Include DeviseAuthProxy::ControllerBehavior in your application controller to enable (by overriding Devise's after_sign_out_path_for).
|
34
|
+
|
35
|
+
|
36
|
+
Set options in a Rails initializer (e.g., `config/intializers/devise.rb`):
|
37
|
+
|
38
|
+
```
|
39
|
+
require 'devise_auth_proxy'
|
40
|
+
|
41
|
+
DeviseAuthProxy.configure do |config|
|
42
|
+
config.env_key = 'HTTP_AUTH_PROXY'
|
43
|
+
config.auto_create = true
|
44
|
+
config.auto_update = true
|
45
|
+
config.attribute_map = { email: 'mail' }
|
46
|
+
config.logout_url = "http://localhost:3000/logout"
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
26
50
|
|
27
51
|
## Development
|
28
52
|
|
@@ -32,7 +56,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
56
|
|
33
57
|
## Contributing
|
34
58
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/me0den/devise_auth_proxy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/me0den/devise_auth_proxy/blob/master/CODE_OF_CONDUCT.md).
|
36
60
|
|
37
61
|
|
38
62
|
## License
|
@@ -41,4 +65,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
65
|
|
42
66
|
## Code of Conduct
|
43
67
|
|
44
|
-
Everyone interacting in the
|
68
|
+
Everyone interacting in the DeviseAuthProxy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/me0den/devise_auth_proxy/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/devise_auth_proxy.rb
CHANGED
@@ -3,7 +3,7 @@ require 'devise_auth_proxy/version'
|
|
3
3
|
|
4
4
|
module DeviseAuthProxy
|
5
5
|
class << self
|
6
|
-
attr_accessor :env_key, :auto_create, :auto_update, :auth_key, :attribute_map, :logout_url
|
6
|
+
attr_accessor :env_key, :auto_create, :auto_update, :auth_key, :attribute_map, :default_role, :logout_url
|
7
7
|
end
|
8
8
|
|
9
9
|
# request.env key for remote user name
|
@@ -23,6 +23,9 @@ module DeviseAuthProxy
|
|
23
23
|
# Map of User model attributes to request.env keys for updating a local user when auto-creation is enabled.
|
24
24
|
self.attribute_map = {}
|
25
25
|
|
26
|
+
# Set default role for new user.
|
27
|
+
self.default_role = []
|
28
|
+
|
26
29
|
# Settings for redirecting to the remote user logout URL
|
27
30
|
# Enable by including DeviseAuthProxy::Controllers::Helpers in ApplicationController
|
28
31
|
# (it overrides Devise's after_sign_out_path_for method).
|
@@ -32,7 +35,7 @@ module DeviseAuthProxy
|
|
32
35
|
yield self
|
33
36
|
end
|
34
37
|
|
35
|
-
def self.
|
38
|
+
def self.proxy_user_id(env)
|
36
39
|
case env_key
|
37
40
|
when Proc
|
38
41
|
env_key.call(env)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DeviseAuthProxy
|
2
|
+
module Controller
|
3
|
+
|
4
|
+
# Modify session controller after user log out.
|
5
|
+
# To redirect user to a custom url.
|
6
|
+
def after_sign_out_path_for(resource_or_scope)
|
7
|
+
DeviseAuthProxy.logout_url if proxy_user_authenticated? and DeviseAuthProxy.logout_url
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def proxy_user_authenticated?
|
14
|
+
DeviseAuthProxy.proxy_user_id(request.env).present?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -27,31 +27,37 @@ module DeviseAuthProxy
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def create_user
|
30
|
-
unless Devise.mappings[:
|
30
|
+
unless Devise.mappings[:admin_user].strategies.include?(:database_authenticatable)
|
31
31
|
return klass.create(user_criterion)
|
32
32
|
end
|
33
33
|
|
34
34
|
random_password = SecureRandom.hex(16)
|
35
|
-
attrs = user_criterion.merge({
|
35
|
+
attrs = user_criterion.merge({
|
36
|
+
password: random_password,
|
37
|
+
password_confirmation: random_password,
|
38
|
+
roles: DeviseAuthProxy.default_role
|
39
|
+
})
|
40
|
+
|
41
|
+
|
36
42
|
klass.create(attrs)
|
37
43
|
end
|
38
44
|
|
39
45
|
def update_user(user)
|
40
|
-
user.update_attributes(
|
46
|
+
user.update_attributes(proxy_user_attributes)
|
41
47
|
end
|
42
48
|
|
43
49
|
protected
|
44
50
|
|
45
|
-
def
|
51
|
+
def proxy_user_attributes
|
46
52
|
DeviseAuthProxy.attribute_map.inject({}) { |h, (k, v)| h[k] = env[v] if env.has_key?(v); h }
|
47
53
|
end
|
48
54
|
|
49
55
|
def user_criterion
|
50
|
-
{auth_key =>
|
56
|
+
{auth_key => proxy_user_id}
|
51
57
|
end
|
52
58
|
|
53
|
-
def
|
54
|
-
DeviseAuthProxy.
|
59
|
+
def proxy_user_id
|
60
|
+
DeviseAuthProxy.proxy_user_id(env)
|
55
61
|
end
|
56
62
|
|
57
63
|
def auth_key
|
@@ -7,10 +7,6 @@ module Devise
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
included do
|
10
|
-
attr_reader :current_password, :password
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethod
|
14
10
|
def self.find_for_auth_proxy_authentication(env)
|
15
11
|
manager = DeviseAuthProxy::Manager.new(self, env)
|
16
12
|
manager.find_or_create_user
|
@@ -5,12 +5,16 @@ module Devise
|
|
5
5
|
class AuthProxyAuthenticatable < Authenticatable
|
6
6
|
|
7
7
|
def valid?
|
8
|
-
DeviseAuthProxy.
|
8
|
+
DeviseAuthProxy.proxy_user_id(env).present?
|
9
9
|
end
|
10
10
|
|
11
11
|
def authenticate!
|
12
12
|
resource = mapping.to.find_for_auth_proxy_authentication(env)
|
13
|
-
|
13
|
+
|
14
|
+
return fail(:invalid) unless resource
|
15
|
+
|
16
|
+
remember_me(resource)
|
17
|
+
success!(resource)
|
14
18
|
end
|
15
19
|
|
16
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_auth_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- QuangTK
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- bin/setup
|
45
45
|
- devise_auth_proxy.gemspec
|
46
46
|
- lib/devise_auth_proxy.rb
|
47
|
+
- lib/devise_auth_proxy/controller.rb
|
47
48
|
- lib/devise_auth_proxy/manager.rb
|
48
49
|
- lib/devise_auth_proxy/model.rb
|
49
50
|
- lib/devise_auth_proxy/strategy.rb
|