devise_custom_authenticatable 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/devise_custom_authenticatable.gemspec +27 -0
- data/lib/devise/models/custom_authenticatable.rb +18 -0
- data/lib/devise/strategies/custom_authenticatable.rb +24 -0
- data/lib/devise_custom_authenticatable/version.rb +3 -0
- data/lib/devise_custom_authenticatable.rb +12 -0
- data/spec/devise/models/custom_authenticatable_spec.rb +44 -0
- data/spec/spec_helper.rb +1 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5199866fec3da5794d0ad77e0c99b7270da070c2
|
4
|
+
data.tar.gz: 5a4fbcdd35b2e525e640850f92121376d313e69c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3fcc76c27370b571b068f3dcaccf32eb96eaf07205fc4f5854edeeb6965cbb4fc2455fadf1567c07d3354f211b8edc18e88c2c1d9a0e9f541da8772bdf30576
|
7
|
+
data.tar.gz: d44cf55749739078861cfbbeabd330c9339e4c59ed70d6dfdc8952440b8c2a22a06426996d919ec9105adaea821f585101efb0c3160e5d262fb8b1a834089a90
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Artūrs Mekšs
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# DeviseCustomAuthenticatable
|
2
|
+
|
3
|
+
Simple way how to customize devise authentication logic and still be inline with all other devise parts
|
4
|
+
|
5
|
+
Extends Devise with new module `:custom_authenticatable`, when used it will call `#valid_for_model_authentication?` method on resource model with password if such defined. Return true in order to authenticate user. If method isn't defined for model or return false/nil then authentication handling will be passed to next strategy e.g. `:database_authenticatable`, if there is no other strategies for resource left then authentication will be failed.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'devise_custom_authenticatable'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install devise_custom_authenticatable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'devise_custom_authenticatable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "devise_custom_authenticatable"
|
8
|
+
spec.version = DeviseCustomAuthenticatable::VERSION
|
9
|
+
spec.authors = ["Artūrs Mekšs"]
|
10
|
+
spec.email = ["arturs.mekss@gmail.com"]
|
11
|
+
spec.description = %q{Simple way to customize devise authentication logic and still be inline with all other devise parts}
|
12
|
+
spec.summary = %q{Extends Devise with new module :custom_authenticatable, when used it will call #valid_for_model_authentication? method on resource model with password if such defined. Return true in order to authenticate user. If method isn't defined for model or return false/nil then authentication handling will be passed to next strategy e.g. :database_authenticatable, if there is no other strategies for resource then authentication will be failed}
|
13
|
+
spec.homepage = "https://github.com/AMekss/devise_custom_authenticatable"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency "devise", "~> 3.0"
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'devise/strategies/custom_authenticatable'
|
2
|
+
|
3
|
+
module Devise::Models
|
4
|
+
module CustomAuthenticatable
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
attr_accessor :password
|
9
|
+
end
|
10
|
+
|
11
|
+
def authenticated_by_any_custom_strategy?(password, *strategies)
|
12
|
+
strategies.any? do |strategy|
|
13
|
+
self.send(:"authenticated_by_#{strategy}_strategy?", password)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'devise/strategies/authenticatable'
|
2
|
+
|
3
|
+
module Devise::Strategies
|
4
|
+
# Strategy for delegateing authentication logic to custom model's method
|
5
|
+
class CustomAuthenticatable < Authenticatable
|
6
|
+
|
7
|
+
def authenticate!
|
8
|
+
resource = valid_password? && mapping.to.find_for_authentication(authentication_hash)
|
9
|
+
|
10
|
+
unless resource.respond_to?(:valid_for_custom_authentication?)
|
11
|
+
return pass
|
12
|
+
end
|
13
|
+
|
14
|
+
if validate(resource){ resource.valid_for_custom_authentication?(password) }
|
15
|
+
success!(resource)
|
16
|
+
else
|
17
|
+
pass
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Warden::Strategies.add(:custom_authenticatable, Devise::Strategies::CustomAuthenticatable)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'devise'
|
3
|
+
|
4
|
+
require 'devise/models/custom_authenticatable'
|
5
|
+
require 'devise/strategies/custom_authenticatable'
|
6
|
+
require 'devise_custom_authenticatable/version'
|
7
|
+
|
8
|
+
Devise.add_module(:custom_authenticatable, {
|
9
|
+
strategy: true,
|
10
|
+
controller: :sessions,
|
11
|
+
model: 'devise/models/custom_authenticatable'
|
12
|
+
})
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CustomAuthenticatableTestClass
|
4
|
+
include Devise::Models::CustomAuthenticatable
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Devise::Models::CustomAuthenticatable do
|
8
|
+
before(:each) do
|
9
|
+
@it = CustomAuthenticatableTestClass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "password attribute accessors should be defined" do
|
13
|
+
@it.password = 'password'
|
14
|
+
expect(@it.password).to eq 'password'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#authenticated_by_any_custom_strategy? helper" do
|
18
|
+
before(:each) do
|
19
|
+
@it.stub(authenticated_by_test1_strategy?: true)
|
20
|
+
@it.stub(authenticated_by_test2_strategy?: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "should call all given strategy methods and" do
|
24
|
+
it "return false if all of them return false" do
|
25
|
+
expect(@it).to receive(:authenticated_by_test1_strategy?).with('password').and_return(false)
|
26
|
+
expect(@it).to receive(:authenticated_by_test2_strategy?).and_return(false)
|
27
|
+
|
28
|
+
expect(@it.authenticated_by_any_custom_strategy?('password', :test1, :test2)).to be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "return true if any of them return true" do
|
32
|
+
expect(@it).to receive(:authenticated_by_test1_strategy?).with('password').and_return(false)
|
33
|
+
expect(@it).to receive(:authenticated_by_test2_strategy?).and_return(true)
|
34
|
+
|
35
|
+
expect(@it.authenticated_by_any_custom_strategy?('password', :test1, :test2)).to be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "return true if all of them return true" do
|
39
|
+
expect(@it.authenticated_by_any_custom_strategy?('password', :test1, :test2)).to be_true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'devise_custom_authenticatable'
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_custom_authenticatable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artūrs Mekšs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: devise
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Simple way to customize devise authentication logic and still be inline
|
70
|
+
with all other devise parts
|
71
|
+
email:
|
72
|
+
- arturs.mekss@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- devise_custom_authenticatable.gemspec
|
85
|
+
- lib/devise/models/custom_authenticatable.rb
|
86
|
+
- lib/devise/strategies/custom_authenticatable.rb
|
87
|
+
- lib/devise_custom_authenticatable.rb
|
88
|
+
- lib/devise_custom_authenticatable/version.rb
|
89
|
+
- spec/devise/models/custom_authenticatable_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/AMekss/devise_custom_authenticatable
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: 'Extends Devise with new module :custom_authenticatable, when used it will
|
115
|
+
call #valid_for_model_authentication? method on resource model with password if
|
116
|
+
such defined. Return true in order to authenticate user. If method isn''t defined
|
117
|
+
for model or return false/nil then authentication handling will be passed to next
|
118
|
+
strategy e.g. :database_authenticatable, if there is no other strategies for resource
|
119
|
+
then authentication will be failed'
|
120
|
+
test_files:
|
121
|
+
- spec/devise/models/custom_authenticatable_spec.rb
|
122
|
+
- spec/spec_helper.rb
|