devise-remote-user 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a9bc050013fedd473e25664f0dfb2cd08ffa238
4
+ data.tar.gz: 2bbb78ac903122fda30d48d4aca37f3fbda0a884
5
+ SHA512:
6
+ metadata.gz: 3faabf423507e954037323361475d52bd764ce49d9d36eb456289aaa01d537692aa3133ac3756b26da9a95f12653e0bfbe081c4d067a378bc079a71b3983c059
7
+ data.tar.gz: 9bc972ecd74d21732ebf255fc06facaa58ed46afd3796f2ecb541bec53c3eaecb917fadaba3b50504549397605109b70e13df4436eaad42526726fe8dffe4c54
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
1
+ The usual github deal: Fork, branch, submit pull request.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2013, Duke University Libraries
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ Redistributions in binary form must reproduce the above copyright notice, this
11
+ list of conditions and the following disclaimer in the documentation and/or
12
+ other materials provided with the distribution.
13
+
14
+ Neither the name of the {organization} nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ devise-remote-user
2
+ ==================
3
+
4
+ A devise extension for remote user authentication.
5
+
6
+ ## Installation
7
+
8
+ Add to Gemfile:
9
+
10
+ ```
11
+ gem 'devise-remote-user'
12
+ ```
13
+
14
+ Then
15
+
16
+ ```
17
+ bundle install
18
+ ```
19
+
20
+ Sorry, there are no generators yet, so ...
21
+
22
+ - Add `:remote_user_authenticatable` symbol to `devise` statement in User model.
23
+ - Add `require 'devise-remote-user'` to devise initializer at `config/initializers/devise.rb`
24
+ - Add `before_filter :authenticate_user!` to ApplicationController, if not already present. This ensures that remote user is logged in locally (via database)
25
+
26
+ Configuration options in `config/intializers/devise.rb`:
27
+
28
+ `remote_user_autocreate` - Boolean (default: false). Whether to auto-create a local user for the remote user.
29
+ `remote_user_env_var` - String (default: 'REMOTE_USER'). Request environment key for the remote user id.
30
+ `remote_user_attribute_map` - Hash (default: {}). Map of User model attributes to request environment keys for updating the local user when auto-creation is enabled.
31
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "devise_remote_user/version"
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "devise-remote-user"
8
+ s.version = DeviseRemoteUser::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["David Chandek-Stark"]
11
+ s.email = ["lib-drs@duke.edu"]
12
+ s.homepage = "http://github.com/duke-libraries/devise-remote-user"
13
+ s.summary = "A devise extension for remote user authentication."
14
+ s.description = "A devise extension for remote user authentication."
15
+ s.license = "BSD"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.extra_rdoc_files = ["LICENSE", "README.md"]
19
+ s.require_paths = ["lib"]
20
+ s.add_dependency "rails", ">= 3.2"
21
+ s.add_dependency "devise"
22
+ end
@@ -0,0 +1,44 @@
1
+ require 'devise_remote_user/strategy'
2
+
3
+ module Devise::Models
4
+ module RemoteUserAuthenticatable
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+
9
+ def find_for_remote_user_authentication(env)
10
+ user = User.where(auth_key => remote_user_id(env)).first
11
+ if !user && Devise.remote_user_autocreate
12
+ user = create_user!(env)
13
+ end
14
+ user
15
+ end
16
+
17
+ private
18
+
19
+ def auth_key
20
+ Devise.remote_user_auth_key || self.authentication_keys.first
21
+ end
22
+
23
+ def create_user!(env)
24
+ random_password = SecureRandom.hex(16)
25
+ attrs = {
26
+ auth_key => remote_user_id(env),
27
+ :password => random_password,
28
+ :password_confirmation => random_password
29
+ }.merge(remote_user_attributes(env))
30
+ User.create! attrs
31
+ end
32
+
33
+ def remote_user_id(env)
34
+ env[Devise.remote_user_env_key]
35
+ end
36
+
37
+ def remote_user_attributes(env)
38
+ Devise.remote_user_attribute_map.inject({}) { |h, (k, v)| h[k] = env[v] if env.has_key?(v); h }
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ require 'devise/strategies/authenticatable'
2
+
3
+ module Devise
4
+
5
+ module Strategies
6
+ class RemoteUserAuthenticatable < Authenticatable
7
+
8
+ def valid?
9
+ env[Devise.remote_user_env_key].present?
10
+ end
11
+
12
+ def authenticate!
13
+ resource = mapping.to.find_for_remote_user_authentication(env)
14
+ resource ? success!(resource) : fail
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+
21
+ Warden::Strategies.add(:remote_user_authenticatable, Devise::Strategies::RemoteUserAuthenticatable)
@@ -0,0 +1,3 @@
1
+ module DeviseRemoteUser
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'devise'
2
+
3
+ module DeviseRemoteUser
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
7
+
8
+ module Devise
9
+ # request.env key for remote user name
10
+ # Set to 'HTTP_REMOTE_USER' in config/initializers/devise.rb if behind reverse proxy
11
+ mattr_accessor :remote_user_env_key
12
+ @@remote_user_env_key = 'REMOTE_USER'
13
+
14
+ # Enable user auto-creation for remote user
15
+ mattr_accessor :remote_user_autocreate
16
+ @@remote_user_autocreate = false
17
+
18
+ # User attribute used for lookup of remote user
19
+ # Defaults to Devise.authentication_keys.first
20
+ mattr_accessor :remote_user_auth_key
21
+ @@remote_user_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
+ mattr_accessor :remote_user_attribute_map
25
+ @@remote_user_attribute_map = {}
26
+ end
27
+
28
+ Devise.add_module(:remote_user_authenticatable,
29
+ :strategy => true,
30
+ :controller => :sessions,
31
+ :model => 'devise_remote_user/model')
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-remote-user
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Chandek-Stark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: devise
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A devise extension for remote user authentication.
42
+ email:
43
+ - lib-drs@duke.edu
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - LICENSE
48
+ - README.md
49
+ files:
50
+ - .gitignore
51
+ - CONTRIBUTING.md
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - devise_remote_user.gemspec
57
+ - lib/devise_remote_user.rb
58
+ - lib/devise_remote_user/model.rb
59
+ - lib/devise_remote_user/strategy.rb
60
+ - lib/devise_remote_user/version.rb
61
+ homepage: http://github.com/duke-libraries/devise-remote-user
62
+ licenses:
63
+ - BSD
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A devise extension for remote user authentication.
85
+ test_files: []