devise_ott 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 +55 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +107 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +26 -0
- data/Rakefile +15 -0
- data/devise_ott.gemspec +29 -0
- data/lib/devise/models/ott_authentication.rb +18 -0
- data/lib/devise/models.rb +7 -0
- data/lib/devise/strategies/ott.rb +42 -0
- data/lib/devise/strategies.rb +5 -0
- data/lib/devise.rb +9 -0
- data/lib/devise_ott/tokens.rb +65 -0
- data/lib/devise_ott/version.rb +3 -0
- data/lib/devise_ott.rb +6 -0
- data/test/devise_ott_test.rb +7 -0
- data/test/rails_app/app/controllers/application_controller.rb +6 -0
- data/test/rails_app/config/application.rb +5 -0
- data/test/rails_app/config/database.yml +3 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/test.rb +31 -0
- data/test/rails_app/config/initializers/devise.rb +173 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +6 -0
- data/test/support/models.rb +6 -0
- data/test/support/schema.rb +15 -0
- data/test/test_helper.rb +15 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0c6d14dde77519a13190e9991d61c15263c1022
|
4
|
+
data.tar.gz: d577d029fc506f7a8e09e0c8f17dafc2c0ec6c12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cfb7a2a80bf88e155d955f401038f214464054f6f51f1b2354d3f4aa4d4fb8f06c9072f58f437f0f749aa5f3700440a91cb654ceff9e360864c15b8e8295729a
|
7
|
+
data.tar.gz: d9b24eec89f9388dcbec1535c1c2b20d4a3d7eaf9c234fcca66e6ee5446762be6ec763c6a0031812cfeb57be6fc0a7a4ae92e968110a285173d29f33933bc483
|
data/.gitignore
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
+
#
|
20
|
+
# * Create a file at ~/.gitignore
|
21
|
+
# * Include files you want ignored
|
22
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
+
#
|
24
|
+
# After doing this, these files will be ignored in all your git projects,
|
25
|
+
# saving you from having to 'pollute' every project you touch with them
|
26
|
+
#
|
27
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
+
#
|
29
|
+
# For MacOS:
|
30
|
+
#
|
31
|
+
#.DS_Store
|
32
|
+
|
33
|
+
# For TextMate
|
34
|
+
#*.tmproj
|
35
|
+
#tmtags
|
36
|
+
|
37
|
+
# For emacs:
|
38
|
+
#*~
|
39
|
+
#\#*
|
40
|
+
#.\#*
|
41
|
+
|
42
|
+
# For vim:
|
43
|
+
#*.swp
|
44
|
+
|
45
|
+
# For redcar:
|
46
|
+
#.redcar
|
47
|
+
|
48
|
+
# For rubinius:
|
49
|
+
#*.rbc
|
50
|
+
|
51
|
+
# Logs
|
52
|
+
*.log
|
53
|
+
|
54
|
+
# Rubymine files
|
55
|
+
.idea
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
devise_ott
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
devise_ott (0.0.1)
|
5
|
+
devise
|
6
|
+
redis
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.0.2)
|
12
|
+
actionpack (= 4.0.2)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (4.0.2)
|
15
|
+
activesupport (= 4.0.2)
|
16
|
+
builder (~> 3.1.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
rack (~> 1.5.2)
|
19
|
+
rack-test (~> 0.6.2)
|
20
|
+
activemodel (4.0.2)
|
21
|
+
activesupport (= 4.0.2)
|
22
|
+
builder (~> 3.1.0)
|
23
|
+
activerecord (4.0.2)
|
24
|
+
activemodel (= 4.0.2)
|
25
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
26
|
+
activesupport (= 4.0.2)
|
27
|
+
arel (~> 4.0.0)
|
28
|
+
activerecord-deprecated_finders (1.0.3)
|
29
|
+
activesupport (4.0.2)
|
30
|
+
i18n (~> 0.6, >= 0.6.4)
|
31
|
+
minitest (~> 4.2)
|
32
|
+
multi_json (~> 1.3)
|
33
|
+
thread_safe (~> 0.1)
|
34
|
+
tzinfo (~> 0.3.37)
|
35
|
+
arel (4.0.1)
|
36
|
+
atomic (1.1.14)
|
37
|
+
bcrypt-ruby (3.1.2)
|
38
|
+
builder (3.1.4)
|
39
|
+
devise (3.2.2)
|
40
|
+
bcrypt-ruby (~> 3.0)
|
41
|
+
orm_adapter (~> 0.1)
|
42
|
+
railties (>= 3.2.6, < 5)
|
43
|
+
thread_safe (~> 0.1)
|
44
|
+
warden (~> 1.2.3)
|
45
|
+
erubis (2.7.0)
|
46
|
+
hike (1.2.3)
|
47
|
+
i18n (0.6.9)
|
48
|
+
mail (2.5.4)
|
49
|
+
mime-types (~> 1.16)
|
50
|
+
treetop (~> 1.4.8)
|
51
|
+
mime-types (1.25.1)
|
52
|
+
minitest (4.7.5)
|
53
|
+
minitest-rails (0.9.2)
|
54
|
+
minitest (~> 4.7)
|
55
|
+
rails (>= 3.0)
|
56
|
+
multi_json (1.8.2)
|
57
|
+
orm_adapter (0.5.0)
|
58
|
+
polyglot (0.3.3)
|
59
|
+
rack (1.5.2)
|
60
|
+
rack-test (0.6.2)
|
61
|
+
rack (>= 1.0)
|
62
|
+
rails (4.0.2)
|
63
|
+
actionmailer (= 4.0.2)
|
64
|
+
actionpack (= 4.0.2)
|
65
|
+
activerecord (= 4.0.2)
|
66
|
+
activesupport (= 4.0.2)
|
67
|
+
bundler (>= 1.3.0, < 2.0)
|
68
|
+
railties (= 4.0.2)
|
69
|
+
sprockets-rails (~> 2.0.0)
|
70
|
+
railties (4.0.2)
|
71
|
+
actionpack (= 4.0.2)
|
72
|
+
activesupport (= 4.0.2)
|
73
|
+
rake (>= 0.8.7)
|
74
|
+
thor (>= 0.18.1, < 2.0)
|
75
|
+
rake (10.1.1)
|
76
|
+
redis (3.0.6)
|
77
|
+
sprockets (2.10.1)
|
78
|
+
hike (~> 1.2)
|
79
|
+
multi_json (~> 1.0)
|
80
|
+
rack (~> 1.0)
|
81
|
+
tilt (~> 1.1, != 1.3.0)
|
82
|
+
sprockets-rails (2.0.1)
|
83
|
+
actionpack (>= 3.0)
|
84
|
+
activesupport (>= 3.0)
|
85
|
+
sprockets (~> 2.8)
|
86
|
+
sqlite3 (1.3.8)
|
87
|
+
thor (0.18.1)
|
88
|
+
thread_safe (0.1.3)
|
89
|
+
atomic
|
90
|
+
tilt (1.4.1)
|
91
|
+
treetop (1.4.15)
|
92
|
+
polyglot
|
93
|
+
polyglot (>= 0.3.1)
|
94
|
+
tzinfo (0.3.38)
|
95
|
+
warden (1.2.3)
|
96
|
+
rack (>= 1.0)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
bundler (~> 1.3)
|
103
|
+
devise_ott!
|
104
|
+
minitest-rails
|
105
|
+
rails
|
106
|
+
rake
|
107
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Iuri Gagnidze
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# DeviseOtt
|
2
|
+
|
3
|
+
{<img src="https://travis-ci.org/igagnidz/devise_ott.png" />}[https://travis-ci.org/igagnidz/devise_ott]
|
4
|
+
{<img src="https://codeclimate.com/github/igagnidz/devise_ott.png" />}[https://codeclimate.com/github/igagnidz/devise_ott]
|
5
|
+
{<img src="http://badge.fury.io/rb/devise_ott.png" />}[http://badge.fury.io/rb/devise_ott]
|
6
|
+
{<img src="https://gemnasium.com/igagnidz/devise_ott.png" alt="Dependency Status" />}[https://gemnasium.com/igagnidz/devise_ott]
|
7
|
+
|
8
|
+
Adds one time token authentication to devise with sign in count and expiration
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'devise_ott'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Add :ott_authentication to your model
|
21
|
+
|
22
|
+
devise :ott_authentication
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
desc 'Default: run tests'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Run Devise unit tests.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
t.warning = false
|
15
|
+
end
|
data/devise_ott.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'devise_ott/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'devise_ott'
|
8
|
+
spec.version = DeviseOtt::VERSION
|
9
|
+
spec.authors = ['Iuri Gagnidze']
|
10
|
+
spec.email = ['igagnidz@gmail.com']
|
11
|
+
spec.description = %q{Adds one time token authentication to devise}
|
12
|
+
spec.summary = %q{Adds one time token authentication to devise}
|
13
|
+
spec.homepage = 'https://github.com/igagnidz/devise_ott'
|
14
|
+
spec.license = 'MIT License'
|
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_dependency 'devise'
|
22
|
+
spec.add_dependency 'redis'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rails'
|
27
|
+
spec.add_development_dependency 'minitest-rails'
|
28
|
+
spec.add_development_dependency 'sqlite3'
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module OttAuthentication
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def find_for_ott_authentication(token)
|
8
|
+
email = DeviseOtt::Tokens.instance.email(token)
|
9
|
+
email && where(email: email).first
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def ott_allowed?(token, resource_id)
|
14
|
+
DeviseOtt::Tokens.instance.access(token, resource_id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Devise
|
2
|
+
module Strategies
|
3
|
+
class Ott < Devise::Strategies::Authenticatable
|
4
|
+
def valid?
|
5
|
+
super || valid_for_ott_auth?
|
6
|
+
end
|
7
|
+
|
8
|
+
def authenticate!
|
9
|
+
ott_token = params[:ott_token]
|
10
|
+
|
11
|
+
return fail! unless mapping.to.respond_to?(:find_for_ott_authentication) # Dont try to authenticate if module is not included
|
12
|
+
|
13
|
+
resource = mapping.to.find_for_ott_authentication(ott_token)
|
14
|
+
|
15
|
+
return fail! unless resource
|
16
|
+
|
17
|
+
if validate(resource){ resource.ott_allowed?(ott_token, resource.email) }
|
18
|
+
success!(resource)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
# Ott Authenticatable can be authenticated with params in any controller and any verb.
|
24
|
+
def valid_params_request?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
# Do not use remember_me behavior with ott token.
|
29
|
+
def remember_me?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check if this is strategy is valid for ott authentication by:
|
34
|
+
#
|
35
|
+
# * If the ott token exists;
|
36
|
+
#
|
37
|
+
def valid_for_ott_auth?
|
38
|
+
params[:ott_token].present?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/devise.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module DeviseOtt
|
4
|
+
class Tokens
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@redis ||= Redis.new(:host => Devise.ott_redis_host)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.finalize(*)
|
12
|
+
@redis.quit
|
13
|
+
end
|
14
|
+
|
15
|
+
# register one time token for given user in redis
|
16
|
+
# the generated token will have a field "email" in order to identify the associated user later
|
17
|
+
def register(token, email, access_count, expire)
|
18
|
+
save_config(token, {email: email, access_count: access_count})
|
19
|
+
@redis.expire(token, expire)
|
20
|
+
|
21
|
+
token
|
22
|
+
end
|
23
|
+
|
24
|
+
# deletes the token
|
25
|
+
def revoke(token)
|
26
|
+
@redis.del(token)
|
27
|
+
end
|
28
|
+
|
29
|
+
# accesses token for given email if it is allowed
|
30
|
+
def access(token, email)
|
31
|
+
config = load_config(token)
|
32
|
+
|
33
|
+
return false unless config
|
34
|
+
return false unless config[:email].to_s == email.to_s
|
35
|
+
return false unless config[:access_count] > 0
|
36
|
+
|
37
|
+
save_config(token, config.merge(access_count: config[:access_count] - 1))
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
# returns email for a given token
|
43
|
+
def email(token)
|
44
|
+
config = load_config(token)
|
45
|
+
config && config[:email]
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def save_config(token, hash)
|
50
|
+
time_left = ttl(token)
|
51
|
+
@redis[token] = Marshal.dump(hash)
|
52
|
+
@redis.expire(token, time_left) if time_left > 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_config(token)
|
56
|
+
if token_data = @redis[token]
|
57
|
+
Marshal.load(token_data)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def ttl(token)
|
62
|
+
@redis.ttl(token)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/devise_ott.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
RailsApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Show full error reports and disable caching
|
11
|
+
config.consider_all_requests_local = true
|
12
|
+
config.action_controller.perform_caching = false
|
13
|
+
|
14
|
+
# Disable request forgery protection in test environment
|
15
|
+
config.action_controller.allow_forgery_protection = false
|
16
|
+
|
17
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
18
|
+
# The :test delivery method accumulates sent emails in the
|
19
|
+
# ActionMailer::Base.deliveries array.
|
20
|
+
config.action_mailer.delivery_method = :test
|
21
|
+
|
22
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
23
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
24
|
+
# like if you have constraints or database-specific column types
|
25
|
+
# config.active_record.schema_format = :sql
|
26
|
+
|
27
|
+
config.action_dispatch.show_exceptions = false
|
28
|
+
config.eager_load = true
|
29
|
+
config.logger = Logger.new(STDOUT)
|
30
|
+
config.active_support.deprecation = :stderr
|
31
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
2
|
+
# four configuration values can also be set straight in your models.
|
3
|
+
Devise.setup do |config|
|
4
|
+
config.secret_key = "d9eb5171c59a4c817f68b0de27b8c1e340c2341b52cdbc60d3083d4e8958532" \
|
5
|
+
"18dcc5f589cafde048faec956b61f864b9b5513ff9ce29bf9e5d58b0f234f8e3b"
|
6
|
+
|
7
|
+
# ==> Mailer Configuration
|
8
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
9
|
+
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
10
|
+
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
11
|
+
|
12
|
+
# Configure the class responsible to send e-mails.
|
13
|
+
# config.mailer = "Devise::Mailer"
|
14
|
+
|
15
|
+
# ==> ORM configuration
|
16
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
17
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
18
|
+
# available as additional gems.
|
19
|
+
require "devise/orm/#{DEVISE_ORM}"
|
20
|
+
|
21
|
+
# ==> Configuration for any authentication mechanism
|
22
|
+
# Configure which keys are used when authenticating a user. By default is
|
23
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
24
|
+
# authenticating a user, both parameters are required. Remember that those
|
25
|
+
# parameters are used only when authenticating and not when retrieving from
|
26
|
+
# session. If you need permissions, you should implement that in a before filter.
|
27
|
+
# You can also supply hash where the value is a boolean expliciting if authentication
|
28
|
+
# should be aborted or not if the value is not present. By default is empty.
|
29
|
+
# config.authentication_keys = [ :email ]
|
30
|
+
|
31
|
+
# Configure parameters from the request object used for authentication. Each entry
|
32
|
+
# given should be a request method and it will automatically be passed to
|
33
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
34
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
35
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
36
|
+
# config.request_keys = []
|
37
|
+
|
38
|
+
# Configure which authentication keys should be case-insensitive.
|
39
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
40
|
+
# to authenticate or find a user. Default is :email.
|
41
|
+
config.case_insensitive_keys = [ :email ]
|
42
|
+
|
43
|
+
# Configure which authentication keys should have whitespace stripped.
|
44
|
+
# These keys will have whitespace before and after removed upon creating or
|
45
|
+
# modifying a user and when used to authenticate or find a user. Default is :email.
|
46
|
+
config.strip_whitespace_keys = [ :email ]
|
47
|
+
|
48
|
+
# Tell if authentication through request.params is enabled. True by default.
|
49
|
+
# config.params_authenticatable = true
|
50
|
+
|
51
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
52
|
+
config.http_authenticatable = true
|
53
|
+
|
54
|
+
# If http headers should be returned for AJAX requests. True by default.
|
55
|
+
# config.http_authenticatable_on_xhr = true
|
56
|
+
|
57
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
58
|
+
# config.http_authentication_realm = "Application"
|
59
|
+
|
60
|
+
# ==> Configuration for :database_authenticatable
|
61
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
62
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
63
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
64
|
+
|
65
|
+
# ==> Configuration for :confirmable
|
66
|
+
# The time you want to give your user to confirm their account. During this time
|
67
|
+
# they will be able to access your application without confirming. Default is nil.
|
68
|
+
# When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming.
|
69
|
+
# You can use this to let your user access some features of your application
|
70
|
+
# without confirming the account, but blocking it after a certain period
|
71
|
+
# (ie 2 days).
|
72
|
+
# config.allow_unconfirmed_access_for = 2.days
|
73
|
+
|
74
|
+
# Defines which key will be used when confirming an account
|
75
|
+
# config.confirmation_keys = [ :email ]
|
76
|
+
|
77
|
+
# ==> Configuration for :rememberable
|
78
|
+
# The time the user will be remembered without asking for credentials again.
|
79
|
+
# config.remember_for = 2.weeks
|
80
|
+
|
81
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
82
|
+
# config.remember_across_browsers = true
|
83
|
+
|
84
|
+
# If true, extends the user's remember period when remembered via cookie.
|
85
|
+
# config.extend_remember_period = false
|
86
|
+
|
87
|
+
# ==> Configuration for :validatable
|
88
|
+
# Range for password length. Default is 8..128.
|
89
|
+
# config.password_length = 8..128
|
90
|
+
|
91
|
+
# Regex to use to validate the email address
|
92
|
+
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
93
|
+
|
94
|
+
# ==> Configuration for :timeoutable
|
95
|
+
# The time you want to timeout the user session without activity. After this
|
96
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
97
|
+
# config.timeout_in = 30.minutes
|
98
|
+
|
99
|
+
# ==> Configuration for :lockable
|
100
|
+
# Defines which strategy will be used to lock an account.
|
101
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
102
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
103
|
+
# config.lock_strategy = :failed_attempts
|
104
|
+
|
105
|
+
# Defines which key will be used when locking and unlocking an account
|
106
|
+
# config.unlock_keys = [ :email ]
|
107
|
+
|
108
|
+
# Defines which strategy will be used to unlock an account.
|
109
|
+
# :email = Sends an unlock link to the user email
|
110
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
111
|
+
# :both = Enables both strategies
|
112
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
113
|
+
# config.unlock_strategy = :both
|
114
|
+
|
115
|
+
# Number of authentication tries before locking an account if lock_strategy
|
116
|
+
# is failed attempts.
|
117
|
+
# config.maximum_attempts = 20
|
118
|
+
|
119
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
120
|
+
# config.unlock_in = 1.hour
|
121
|
+
|
122
|
+
# ==> Configuration for :recoverable
|
123
|
+
#
|
124
|
+
# Defines which key will be used when recovering the password for an account
|
125
|
+
# config.reset_password_keys = [ :email ]
|
126
|
+
|
127
|
+
# Time interval you can reset your password with a reset password key.
|
128
|
+
# Don't put a too small interval or your users won't have the time to
|
129
|
+
# change their passwords.
|
130
|
+
config.reset_password_within = 2.hours
|
131
|
+
|
132
|
+
# Setup a pepper to generate the encrypted password.
|
133
|
+
config.pepper = "d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a"
|
134
|
+
|
135
|
+
# ==> Configuration for :token_authenticatable
|
136
|
+
# Defines name of the authentication token params key
|
137
|
+
# config.token_authentication_key = :auth_token
|
138
|
+
|
139
|
+
# ==> Scopes configuration
|
140
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
141
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
142
|
+
# are using only default views.
|
143
|
+
# config.scoped_views = false
|
144
|
+
|
145
|
+
# Configure the default scope given to Warden. By default it's the first
|
146
|
+
# devise role declared in your routes (usually :user).
|
147
|
+
# config.default_scope = :user
|
148
|
+
|
149
|
+
# Configure sign_out behavior.
|
150
|
+
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
151
|
+
# The default is true, which means any logout action will sign out all active scopes.
|
152
|
+
# config.sign_out_all_scopes = true
|
153
|
+
|
154
|
+
# ==> Navigation configuration
|
155
|
+
# Lists the formats that should be treated as navigational. Formats like
|
156
|
+
# :html, should redirect to the sign in page when the user does not have
|
157
|
+
# access, but formats like :xml or :json, should return 401.
|
158
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
159
|
+
# should add them to the navigational formats lists. Default is [:html]
|
160
|
+
# config.navigational_formats = [:html, :iphone]
|
161
|
+
|
162
|
+
# The default HTTP method used to sign out a resource. Default is :get.
|
163
|
+
# config.sign_out_via = :get
|
164
|
+
|
165
|
+
# ==> Warden configuration
|
166
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
167
|
+
# change the failure app, you can configure them inside the config.warden block.
|
168
|
+
#
|
169
|
+
# config.warden do |manager|
|
170
|
+
# manager.failure_app = AnotherApp
|
171
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
172
|
+
# end
|
173
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
4
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
5
|
+
get ':controller(/:action(/:id(.:format)))'
|
6
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
5
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
6
|
+
ActiveRecord::Migration.verbose = false
|
7
|
+
|
8
|
+
ActiveRecord::Schema.define do
|
9
|
+
create_table :users, :force => true do |t|
|
10
|
+
t.string "email"
|
11
|
+
t.string "type"
|
12
|
+
t.datetime "created_at"
|
13
|
+
t.datetime "updated_at"
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Set RAILS_ENV to test
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
|
+
|
4
|
+
DEVISE_ORM = (ENV['DEVISE_ORM'] || :active_record).to_sym
|
5
|
+
TEST_ROOT = File.expand_path('../', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'devise'
|
9
|
+
require 'devise_ott'
|
10
|
+
require 'rails/test_help'
|
11
|
+
require 'minitest/rails'
|
12
|
+
require 'rails_app/config/environment'
|
13
|
+
|
14
|
+
|
15
|
+
Dir[File.join(TEST_ROOT, 'support/*.rb')].each{ |f| require f }
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_ott
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iuri Gagnidze
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: devise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Adds one time token authentication to devise
|
112
|
+
email:
|
113
|
+
- igagnidz@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".ruby-gemset"
|
120
|
+
- ".ruby-version"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.rdoc
|
126
|
+
- Rakefile
|
127
|
+
- devise_ott.gemspec
|
128
|
+
- lib/devise.rb
|
129
|
+
- lib/devise/models.rb
|
130
|
+
- lib/devise/models/ott_authentication.rb
|
131
|
+
- lib/devise/strategies.rb
|
132
|
+
- lib/devise/strategies/ott.rb
|
133
|
+
- lib/devise_ott.rb
|
134
|
+
- lib/devise_ott/tokens.rb
|
135
|
+
- lib/devise_ott/version.rb
|
136
|
+
- test/devise_ott_test.rb
|
137
|
+
- test/rails_app/app/controllers/application_controller.rb
|
138
|
+
- test/rails_app/config/application.rb
|
139
|
+
- test/rails_app/config/database.yml
|
140
|
+
- test/rails_app/config/environment.rb
|
141
|
+
- test/rails_app/config/environments/test.rb
|
142
|
+
- test/rails_app/config/initializers/devise.rb
|
143
|
+
- test/rails_app/config/initializers/secret_token.rb
|
144
|
+
- test/rails_app/config/routes.rb
|
145
|
+
- test/support/models.rb
|
146
|
+
- test/support/schema.rb
|
147
|
+
- test/test_helper.rb
|
148
|
+
homepage: https://github.com/igagnidz/devise_ott
|
149
|
+
licenses:
|
150
|
+
- MIT License
|
151
|
+
metadata: {}
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.2.0.rc.1
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: Adds one time token authentication to devise
|
172
|
+
test_files:
|
173
|
+
- test/devise_ott_test.rb
|
174
|
+
- test/rails_app/app/controllers/application_controller.rb
|
175
|
+
- test/rails_app/config/application.rb
|
176
|
+
- test/rails_app/config/database.yml
|
177
|
+
- test/rails_app/config/environment.rb
|
178
|
+
- test/rails_app/config/environments/test.rb
|
179
|
+
- test/rails_app/config/initializers/devise.rb
|
180
|
+
- test/rails_app/config/initializers/secret_token.rb
|
181
|
+
- test/rails_app/config/routes.rb
|
182
|
+
- test/support/models.rb
|
183
|
+
- test/support/schema.rb
|
184
|
+
- test/test_helper.rb
|