devise_auth_proxy 0.1.13 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +101 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/devise_auth_proxy.gemspec +30 -0
- data/lib/devise_auth_proxy.rb +53 -0
- data/lib/devise_auth_proxy/manager.rb +65 -0
- data/lib/devise_auth_proxy/model.rb +17 -0
- data/lib/devise_auth_proxy/strategy.rb +24 -0
- data/lib/devise_auth_proxy/version.rb +3 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6af0161c4e1be59158764e92b23d952b05fbadd5bb598721863cfe0ab219e162
|
4
|
+
data.tar.gz: 741d9df632d84752cf516922a340736080a46ac3fd9406eeb0fc6fa324136dac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ad9668c368c4789a8cdcc6bda6128e9c8d3ceeec19d525fadab659150ecbce004fb0c457e12416b0231f4eb0ac38eb083ebf8812faf267a3571ee642025c6c
|
7
|
+
data.tar.gz: c4e24436f33df434673b83045155a60d68eca83f7419e9e19ae01c6bea3bd9e81620e38d38dac9b9c4ecc2de61519a73cd737179f76e240c972386491eef0a20
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tkquang@fossil.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
devise_auth_proxy (0.1.18)
|
5
|
+
devise
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (6.0.3.3)
|
11
|
+
actionview (= 6.0.3.3)
|
12
|
+
activesupport (= 6.0.3.3)
|
13
|
+
rack (~> 2.0, >= 2.0.8)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (6.0.3.3)
|
18
|
+
activesupport (= 6.0.3.3)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activesupport (6.0.3.3)
|
24
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
|
+
i18n (>= 0.7, < 2)
|
26
|
+
minitest (~> 5.1)
|
27
|
+
tzinfo (~> 1.1)
|
28
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
29
|
+
bcrypt (3.1.16)
|
30
|
+
builder (3.2.4)
|
31
|
+
concurrent-ruby (1.1.7)
|
32
|
+
crass (1.0.6)
|
33
|
+
devise (4.7.3)
|
34
|
+
bcrypt (~> 3.0)
|
35
|
+
orm_adapter (~> 0.1)
|
36
|
+
railties (>= 4.1.0)
|
37
|
+
responders
|
38
|
+
warden (~> 1.2.3)
|
39
|
+
diff-lcs (1.4.4)
|
40
|
+
erubi (1.9.0)
|
41
|
+
i18n (1.8.5)
|
42
|
+
concurrent-ruby (~> 1.0)
|
43
|
+
loofah (2.7.0)
|
44
|
+
crass (~> 1.0.2)
|
45
|
+
nokogiri (>= 1.5.9)
|
46
|
+
method_source (1.0.0)
|
47
|
+
mini_portile2 (2.4.0)
|
48
|
+
minitest (5.14.2)
|
49
|
+
nokogiri (1.10.10)
|
50
|
+
mini_portile2 (~> 2.4.0)
|
51
|
+
orm_adapter (0.5.0)
|
52
|
+
rack (2.2.3)
|
53
|
+
rack-test (1.1.0)
|
54
|
+
rack (>= 1.0, < 3)
|
55
|
+
rails-dom-testing (2.0.3)
|
56
|
+
activesupport (>= 4.2.0)
|
57
|
+
nokogiri (>= 1.6)
|
58
|
+
rails-html-sanitizer (1.3.0)
|
59
|
+
loofah (~> 2.3)
|
60
|
+
railties (6.0.3.3)
|
61
|
+
actionpack (= 6.0.3.3)
|
62
|
+
activesupport (= 6.0.3.3)
|
63
|
+
method_source
|
64
|
+
rake (>= 0.8.7)
|
65
|
+
thor (>= 0.20.3, < 2.0)
|
66
|
+
rake (12.3.3)
|
67
|
+
responders (3.0.1)
|
68
|
+
actionpack (>= 5.0)
|
69
|
+
railties (>= 5.0)
|
70
|
+
rspec (3.9.0)
|
71
|
+
rspec-core (~> 3.9.0)
|
72
|
+
rspec-expectations (~> 3.9.0)
|
73
|
+
rspec-mocks (~> 3.9.0)
|
74
|
+
rspec-core (3.9.2)
|
75
|
+
rspec-support (~> 3.9.3)
|
76
|
+
rspec-expectations (3.9.2)
|
77
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
+
rspec-support (~> 3.9.0)
|
79
|
+
rspec-mocks (3.9.1)
|
80
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
+
rspec-support (~> 3.9.0)
|
82
|
+
rspec-support (3.9.3)
|
83
|
+
thor (1.0.1)
|
84
|
+
thread_safe (0.3.6)
|
85
|
+
tzinfo (1.2.7)
|
86
|
+
thread_safe (~> 0.1)
|
87
|
+
warden (1.2.9)
|
88
|
+
rack (>= 2.0.9)
|
89
|
+
zeitwerk (2.4.0)
|
90
|
+
|
91
|
+
PLATFORMS
|
92
|
+
ruby
|
93
|
+
|
94
|
+
DEPENDENCIES
|
95
|
+
devise
|
96
|
+
devise_auth_proxy!
|
97
|
+
rake (~> 12.0)
|
98
|
+
rspec (~> 3.0)
|
99
|
+
|
100
|
+
BUNDLED WITH
|
101
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 QuangTK
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# DeviseAuthProxy
|
2
|
+
|
3
|
+
A devise extension for proxy user authentication.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/devise_auth_proxy.svg)](http://badge.fury.io/rb/devise_auth_proxy)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'devise_auth_proxy'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install devise_auth_proxy
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
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
|
+
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
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.
|
54
|
+
|
55
|
+
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).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
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).
|
60
|
+
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
65
|
+
|
66
|
+
## Code of Conduct
|
67
|
+
|
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/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "devise_auth_proxy"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require_relative 'lib/devise_auth_proxy/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "devise_auth_proxy"
|
7
|
+
spec.version = DeviseAuthProxy::VERSION
|
8
|
+
spec.authors = ["QuangTK"]
|
9
|
+
spec.email = ["tkquang@fossil.com"]
|
10
|
+
|
11
|
+
spec.summary = "For authentication through proxy auth"
|
12
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
+
spec.homepage = "https://github.com/me0den/devise_auth_proxy"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "devise"
|
30
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'devise'
|
2
|
+
require 'devise_auth_proxy/version'
|
3
|
+
|
4
|
+
module DeviseAuthProxy
|
5
|
+
class << self
|
6
|
+
attr_accessor :env_key, :auto_create, :auto_update, :auth_key, :attribute_map, :default_role, :logout_url
|
7
|
+
end
|
8
|
+
|
9
|
+
# request.env key for remote user name
|
10
|
+
# Set to 'HTTP_AUTH_PROXY' in config/initializers/devise.rb if behind reverse proxy
|
11
|
+
self.env_key = 'AUTH_PROXY'
|
12
|
+
|
13
|
+
# Enable user auto-creation of user from proxy user attributes
|
14
|
+
self.auto_create = false
|
15
|
+
|
16
|
+
# Enable user auto-update of user attributes from proxy user attributes
|
17
|
+
self.auto_update = false
|
18
|
+
|
19
|
+
# User attribute used for lookup of proxy user
|
20
|
+
# Defaults to Devise.authentication_keys.first
|
21
|
+
self.auth_key = nil
|
22
|
+
|
23
|
+
# Map of User model attributes to request.env keys for updating a local user when auto-creation is enabled.
|
24
|
+
self.attribute_map = {}
|
25
|
+
|
26
|
+
# Set default role for new user.
|
27
|
+
self.default_role = []
|
28
|
+
|
29
|
+
# Settings for redirecting to the remote user logout URL
|
30
|
+
# Enable by including DeviseAuthProxy::Controllers::Helpers in ApplicationController
|
31
|
+
# (it overrides Devise's after_sign_out_path_for method).
|
32
|
+
self.logout_url = '/'
|
33
|
+
|
34
|
+
def self.configure
|
35
|
+
yield self
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.proxy_user_id(env)
|
39
|
+
case env_key
|
40
|
+
when Proc
|
41
|
+
env_key.call(env)
|
42
|
+
else
|
43
|
+
env[env_key]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Error < StandardError; end
|
48
|
+
end
|
49
|
+
|
50
|
+
Devise.add_module(:auth_proxy_authenticatable,
|
51
|
+
:strategy => true,
|
52
|
+
:controller => :sessions,
|
53
|
+
:model => 'devise_auth_proxy/model')
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module DeviseAuthProxy
|
2
|
+
|
3
|
+
#
|
4
|
+
# The Manager class is responsible for connecting the appliation's User
|
5
|
+
# class with proxy user information in the request environment.
|
6
|
+
#
|
7
|
+
class Manager
|
8
|
+
|
9
|
+
attr_reader :klass, :env
|
10
|
+
|
11
|
+
def initialize(klass, env)
|
12
|
+
@klass = klass
|
13
|
+
@env = env
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_or_create_user
|
17
|
+
user = find_user
|
18
|
+
if !user && DeviseAuthProxy.auto_create
|
19
|
+
user = create_user
|
20
|
+
end
|
21
|
+
update_user(user) if user && DeviseAuthProxy.auto_update
|
22
|
+
user
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_user
|
26
|
+
klass.where(user_criterion).first
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_user
|
30
|
+
unless Devise.mappings[:admin_user].strategies.include?(:database_authenticatable)
|
31
|
+
return klass.create(user_criterion)
|
32
|
+
end
|
33
|
+
|
34
|
+
random_password = SecureRandom.hex(16)
|
35
|
+
attrs = user_criterion.merge({
|
36
|
+
password: random_password,
|
37
|
+
password_confirmation: random_password,
|
38
|
+
roles: DeviseAuthProxy.default_role
|
39
|
+
})
|
40
|
+
klass.create(attrs)
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_user(user)
|
44
|
+
user.update_attributes(proxy_user_attributes)
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def proxy_user_attributes
|
50
|
+
DeviseAuthProxy.attribute_map.inject({}) { |h, (k, v)| h[k] = env[v] if env.has_key?(v); h }
|
51
|
+
end
|
52
|
+
|
53
|
+
def user_criterion
|
54
|
+
{auth_key => proxy_user_id}
|
55
|
+
end
|
56
|
+
|
57
|
+
def proxy_user_id
|
58
|
+
DeviseAuthProxy.proxy_user_id(env)
|
59
|
+
end
|
60
|
+
|
61
|
+
def auth_key
|
62
|
+
DeviseAuthProxy.auth_key || Devise.authentication_keys.first
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'devise_auth_proxy/strategy'
|
2
|
+
require 'devise_auth_proxy/manager'
|
3
|
+
|
4
|
+
module Devise
|
5
|
+
module Models
|
6
|
+
module AuthProxyAuthenticatable
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
def self.find_for_auth_proxy_authentication(env)
|
11
|
+
manager = DeviseAuthProxy::Manager.new(self, env)
|
12
|
+
manager.find_or_create_user
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'devise/strategies/authenticatable'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Strategies
|
5
|
+
class AuthProxyAuthenticatable < Authenticatable
|
6
|
+
|
7
|
+
def valid?
|
8
|
+
DeviseAuthProxy.proxy_user_id(env).present?
|
9
|
+
end
|
10
|
+
|
11
|
+
def authenticate!
|
12
|
+
resource = mapping.to.find_for_auth_proxy_authentication(env)
|
13
|
+
|
14
|
+
return fail(:invalid) unless resource
|
15
|
+
|
16
|
+
remember_me(resource)
|
17
|
+
success!(resource)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Warden::Strategies.add(:auth_proxy_authenticatable, Devise::Strategies::AuthProxyAuthenticatable)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- QuangTK
|
@@ -30,8 +30,25 @@ email:
|
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
|
-
files:
|
34
|
-
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- devise_auth_proxy.gemspec
|
46
|
+
- lib/devise_auth_proxy.rb
|
47
|
+
- lib/devise_auth_proxy/manager.rb
|
48
|
+
- lib/devise_auth_proxy/model.rb
|
49
|
+
- lib/devise_auth_proxy/strategy.rb
|
50
|
+
- lib/devise_auth_proxy/version.rb
|
51
|
+
homepage: https://github.com/me0den/devise_auth_proxy
|
35
52
|
licenses:
|
36
53
|
- MIT
|
37
54
|
metadata: {}
|