devise_auth_proxy 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8846af07e2b4f12a6c281145c42e735a9fcd0ce03ea977616183451c73aeb08e
4
- data.tar.gz: d018490c545869580150831ffddb5bc2b16525d2efc366834ad6d3dd4a27f5df
3
+ metadata.gz: fb482273df7b5210882d40b4baa9a524f8981a885a4165d57ff1e12255ad057f
4
+ data.tar.gz: 2d452531bc30dcf873834a9412ec111d14eac314c28ae20939da5451a388f066
5
5
  SHA512:
6
- metadata.gz: c769602495ca09310aa056dcdb21260f975d38321e077e4e77eec66b5ce842c85e368e51dfe0b2225ccdbcb0d9f855da392100abb872ecf705b19d52cbfdd3fc
7
- data.tar.gz: 3dfb5e2f40dc920369e984f4c23f43d48d5a3e0d3550732d66436b048c6f787274e411e02ee6d913e5e20c87b3486547349316054ce6751e87bece076f09c906
6
+ metadata.gz: 3c3430f08cd3f30e177905833fa01140257383a826f5403077c13603494a35789bae094b7ae0bd0fdceabc9b8ae6abfa09aec6a2e5bb198aa1e07ede468342a4
7
+ data.tar.gz: dd23d00047233114e3cda97f6bc93094a020670927a6bf728fdd14ba30dadf1f985f82e57fd2afbb5b4cfecdfc01f2ae70cf6a9c98f49623b063f5da3eb30215
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -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
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in devise-auth_proxy.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "devise"
@@ -0,0 +1,101 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise_auth_proxy (0.1.14)
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
@@ -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.
@@ -0,0 +1,44 @@
1
+ # Devise::AuthProxy
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/devise/auth_proxy`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
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
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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/[USERNAME]/devise-auth_proxy/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Devise::AuthProxy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/devise-auth_proxy/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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,50 @@
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, :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
+ # Settings for redirecting to the remote user logout URL
27
+ # Enable by including DeviseAuthProxy::Controllers::Helpers in ApplicationController
28
+ # (it overrides Devise's after_sign_out_path_for method).
29
+ self.logout_url = '/'
30
+
31
+ def self.configure
32
+ yield self
33
+ end
34
+
35
+ def self.remote_user_id env
36
+ case env_key
37
+ when Proc
38
+ env_key.call(env)
39
+ else
40
+ env[env_key]
41
+ end
42
+ end
43
+
44
+ class Error < StandardError; end
45
+ end
46
+
47
+ Devise.add_module(:auth_proxy_authenticatable,
48
+ :strategy => true,
49
+ :controller => :sessions,
50
+ :model => 'devise_auth_proxy/model')
@@ -0,0 +1,61 @@
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[: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({password: random_password, password_confirmation: random_password})
36
+ klass.create(attrs)
37
+ end
38
+
39
+ def update_user(user)
40
+ user.update_attributes(remote_user_attributes)
41
+ end
42
+
43
+ protected
44
+
45
+ def remote_user_attributes
46
+ DeviseAuthProxy.attribute_map.inject({}) { |h, (k, v)| h[k] = env[v] if env.has_key?(v); h }
47
+ end
48
+
49
+ def user_criterion
50
+ {auth_key => remote_user_id}
51
+ end
52
+
53
+ def remote_user_id
54
+ DeviseAuthProxy.remote_user_id(env)
55
+ end
56
+
57
+ def auth_key
58
+ DeviseAuthProxy.auth_key || Devise.authentication_keys.first
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
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
+ attr_reader :current_password, :password
11
+ end
12
+
13
+ module ClassMethod
14
+ def self.find_for_auth_proxy_authentication(env)
15
+ manager = DeviseAuthProxy::Manager.new(self, env)
16
+ manager.find_or_create_user
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'devise/strategies/authenticatable'
2
+
3
+ module Devise
4
+ module Strategies
5
+ class AuthProxyAuthenticatable < Authenticatable
6
+
7
+ def valid?
8
+ DeviseAuthProxy.remote_user_id(env).present?
9
+ end
10
+
11
+ def authenticate!
12
+ resource = mapping.to.find_for_auth_proxy_authentication(env)
13
+ resource ? success!(resource) : fail
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ Warden::Strategies.add(:auth_proxy_authenticatable, Devise::Strategies::AuthProxyAuthenticatable)
@@ -0,0 +1,3 @@
1
+ module DeviseAuthProxy
2
+ VERSION = "0.1.14"
3
+ end
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.13
4
+ version: 0.1.14
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
- homepage:
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: {}