devise_token_auth 0.1.21.alpha2 → 0.1.23.alpha1
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 +4 -4
- data/README.md +52 -48
- data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +3 -1
- data/lib/devise_token_auth/version.rb +1 -1
- data/lib/generators/devise_token_auth/install_generator.rb +35 -25
- data/test/dummy/config/application.yml +6 -6
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +128 -0
- data/test/dummy/log/test.log +62277 -0
- data/test/dummy/tmp/generators/app/models/user.rb +3 -0
- data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +22 -0
- data/test/dummy/tmp/generators/db/migrate/20140721004743_devise_token_auth_create_users.rb +56 -0
- data/test/lib/generators/devise_token_auth/install_generator_test.rb +168 -6
- data/test/test_helper.rb +8 -0
- metadata +11 -8
- data/app/assets/javascripts/devise_token_auth/application.js +0 -13
- data/app/assets/stylesheets/devise_token_auth/application.css +0 -15
- data/app/helpers/devise_token_auth/application_helper.rb +0 -4
@@ -0,0 +1,22 @@
|
|
1
|
+
DeviseTokenAuth.setup do |config|
|
2
|
+
# By default the authorization headers will change after each request. The
|
3
|
+
# client is responsible for keeping track of the changing tokens. Change
|
4
|
+
# this to false to prevent the Authorization header from changing after
|
5
|
+
# each request.
|
6
|
+
#config.change_headers_on_each_request = true
|
7
|
+
|
8
|
+
# By default, users will need to re-authenticate after 2 weeks. This setting
|
9
|
+
# determines how long tokens will remain valid after they are issued.
|
10
|
+
#config.token_lifespan = 2.weeks
|
11
|
+
|
12
|
+
# Sometimes it's necessary to make several requests to the API at the same
|
13
|
+
# time. In this case, each request in the batch will need to share the same
|
14
|
+
# auth token. This setting determines how far apart the requests can be while
|
15
|
+
# still using the same auth token.
|
16
|
+
#config.batch_request_buffer_throttle = 5.seconds
|
17
|
+
|
18
|
+
# This route will be the prefix for all oauth2 redirect callbacks. For
|
19
|
+
# example, using the default '/omniauth', the github oauth2 provider will
|
20
|
+
# redirect successful authentications to '/omniauth/github/callback'
|
21
|
+
#config.omniauth_prefix = "/omniauth"
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class DeviseTokenAuthCreateUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:users) do |t|
|
4
|
+
## Database authenticatable
|
5
|
+
t.string :email
|
6
|
+
t.string :encrypted_password, :null => false, :default => ""
|
7
|
+
|
8
|
+
## Recoverable
|
9
|
+
t.string :reset_password_token
|
10
|
+
t.datetime :reset_password_sent_at
|
11
|
+
t.string :reset_password_redirect_url
|
12
|
+
|
13
|
+
## Rememberable
|
14
|
+
t.datetime :remember_created_at
|
15
|
+
|
16
|
+
## Trackable
|
17
|
+
t.integer :sign_in_count, :default => 0, :null => false
|
18
|
+
t.datetime :current_sign_in_at
|
19
|
+
t.datetime :last_sign_in_at
|
20
|
+
t.string :current_sign_in_ip
|
21
|
+
t.string :last_sign_in_ip
|
22
|
+
|
23
|
+
## Confirmable
|
24
|
+
t.string :confirmation_token
|
25
|
+
t.datetime :confirmed_at
|
26
|
+
t.datetime :confirmation_sent_at
|
27
|
+
t.string :confirm_success_url
|
28
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
29
|
+
|
30
|
+
## Lockable
|
31
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
32
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
33
|
+
# t.datetime :locked_at
|
34
|
+
|
35
|
+
## User Info
|
36
|
+
t.string :name
|
37
|
+
t.string :nickname
|
38
|
+
t.string :image
|
39
|
+
|
40
|
+
## unique oauth id
|
41
|
+
t.string :provider
|
42
|
+
t.string :uid, :null => false, :default => ""
|
43
|
+
|
44
|
+
## Tokens
|
45
|
+
t.text :tokens
|
46
|
+
|
47
|
+
t.timestamps
|
48
|
+
end
|
49
|
+
|
50
|
+
add_index :users, :email
|
51
|
+
add_index :users, :uid, :unique => true
|
52
|
+
add_index :users, :reset_password_token, :unique => true
|
53
|
+
# add_index :users, :confirmation_token, :unique => true
|
54
|
+
# add_index :users, :unlock_token, :unique => true
|
55
|
+
end
|
56
|
+
end
|
@@ -1,16 +1,178 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'fileutils'
|
2
3
|
require 'generators/devise_token_auth/install_generator'
|
3
4
|
|
4
5
|
module DeviseTokenAuth
|
5
6
|
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
7
|
tests InstallGenerator
|
7
8
|
destination Rails.root.join('tmp/generators')
|
8
|
-
setup :prepare_destination
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
describe 'default values, clean install' do
|
11
|
+
setup :prepare_destination
|
12
|
+
|
13
|
+
before do
|
14
|
+
run_generator
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'user model is created, concern is included' do
|
18
|
+
assert_file 'app/models/user.rb' do |model|
|
19
|
+
assert_match(/include DeviseTokenAuth::Concerns::User/, model)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'initializer is created' do
|
24
|
+
assert_file 'config/initializers/devise_token_auth.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'migration is created' do
|
28
|
+
assert_migration 'db/migrate/devise_token_auth_create_users.rb'
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'subsequent runs raise no errors' do
|
32
|
+
run_generator
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'existing user model' do
|
37
|
+
setup :prepare_destination
|
38
|
+
|
39
|
+
before do
|
40
|
+
@dir = File.join(destination_root, "app", "models")
|
41
|
+
|
42
|
+
@fname = File.join(@dir, "user.rb")
|
43
|
+
|
44
|
+
# make dir if not exists
|
45
|
+
FileUtils.mkdir_p(@dir)
|
46
|
+
|
47
|
+
@f = File.open(@fname, 'w') {|f|
|
48
|
+
f.write <<-RUBY
|
49
|
+
class User < ActiveRecord::Base
|
50
|
+
|
51
|
+
def whatever
|
52
|
+
puts 'whatever'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
RUBY
|
56
|
+
}
|
57
|
+
|
58
|
+
run_generator
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'user concern is injected into existing model' do
|
62
|
+
assert_file 'app/models/user.rb' do |model|
|
63
|
+
assert_match(/include DeviseTokenAuth::Concerns::User/, model)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'subsequent runs do not modify file' do
|
68
|
+
run_generator
|
69
|
+
assert_file 'app/models/user.rb' do |model|
|
70
|
+
matches = model.scan(/include DeviseTokenAuth::Concerns::User/m).size
|
71
|
+
assert_equal 1, matches
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
describe 'routes' do
|
78
|
+
setup :prepare_destination
|
79
|
+
|
80
|
+
before do
|
81
|
+
@dir = File.join(destination_root, "config")
|
82
|
+
|
83
|
+
@fname = File.join(@dir, "routes.rb")
|
84
|
+
|
85
|
+
# make dir if not exists
|
86
|
+
FileUtils.mkdir_p(@dir)
|
87
|
+
|
88
|
+
@f = File.open(@fname, 'w') {|f|
|
89
|
+
f.write <<-RUBY
|
90
|
+
Rails.application.routes.draw do
|
91
|
+
patch '/chong', to: 'bong#index'
|
92
|
+
end
|
93
|
+
RUBY
|
94
|
+
}
|
95
|
+
|
96
|
+
run_generator
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'route method is appended to routes file' do
|
100
|
+
assert_file 'config/routes.rb' do |routes|
|
101
|
+
assert_match(/mount_devise_token_auth_for 'User', at: '\/auth'/, routes)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test 'subsequent runs do not modify file' do
|
106
|
+
run_generator
|
107
|
+
assert_file 'config/routes.rb' do |routes|
|
108
|
+
matches = routes.scan(/mount_devise_token_auth_for 'User', at: '\/auth'/m).size
|
109
|
+
assert_equal 1, matches
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'subsequent models' do
|
114
|
+
before do
|
115
|
+
run_generator %w(Mang /bong)
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'migration is created' do
|
119
|
+
assert_migration 'db/migrate/devise_token_auth_create_mangs.rb'
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'route method is appended to routes file' do
|
123
|
+
assert_file 'config/routes.rb' do |routes|
|
124
|
+
assert_match(/mount_devise_token_auth_for 'Mang', at: '\/bong'/, routes)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'devise_for block is appended to routes file' do
|
129
|
+
assert_file 'config/routes.rb' do |routes|
|
130
|
+
assert_match(/as :mang do/, routes)
|
131
|
+
assert_match(/# Define routes for Mang within this block./, routes)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'application controller' do
|
138
|
+
setup :prepare_destination
|
139
|
+
|
140
|
+
before do
|
141
|
+
@dir = File.join(destination_root, "app", "controllers")
|
142
|
+
|
143
|
+
@fname = File.join(@dir, "application_controller.rb")
|
144
|
+
|
145
|
+
# make dir if not exists
|
146
|
+
FileUtils.mkdir_p(@dir)
|
147
|
+
|
148
|
+
@f = File.open(@fname, 'w') {|f|
|
149
|
+
f.write <<-RUBY
|
150
|
+
class ApplicationController < ActionController::Base
|
151
|
+
respond_to :json
|
152
|
+
|
153
|
+
def whatever
|
154
|
+
'whatever'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
RUBY
|
158
|
+
}
|
159
|
+
|
160
|
+
run_generator
|
161
|
+
end
|
162
|
+
|
163
|
+
test 'controller concern is appended to application controller' do
|
164
|
+
assert_file 'app/controllers/application_controller.rb' do |controller|
|
165
|
+
assert_match(/include DeviseTokenAuth::Concerns::SetUserByToken/, controller)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
test 'subsequent runs do not modify file' do
|
170
|
+
run_generator
|
171
|
+
assert_file 'app/controllers/application_controller.rb' do |controller|
|
172
|
+
matches = controller.scan(/include DeviseTokenAuth::Concerns::SetUserByToken/m).size
|
173
|
+
assert_equal 1, matches
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
15
177
|
end
|
16
178
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
require "codeclimate-test-reporter"
|
2
|
+
#require 'simplecov'
|
3
|
+
|
4
|
+
#SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
#SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
#CodeClimate::TestReporter::Formatter
|
7
|
+
#]
|
8
|
+
|
9
|
+
#SimpleCov.start 'rails'
|
2
10
|
CodeClimate::TestReporter.start
|
3
11
|
|
4
12
|
ENV["RAILS_ENV"] = "test"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_token_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lynn Hurley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1
|
19
|
+
version: '4.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.1
|
26
|
+
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: devise
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,8 +90,6 @@ files:
|
|
90
90
|
- LICENSE
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
|
-
- app/assets/javascripts/devise_token_auth/application.js
|
94
|
-
- app/assets/stylesheets/devise_token_auth/application.css
|
95
93
|
- app/controllers/devise_token_auth/application_controller.rb
|
96
94
|
- app/controllers/devise_token_auth/auth_controller.rb
|
97
95
|
- app/controllers/devise_token_auth/concerns/set_user_by_token.rb
|
@@ -99,7 +97,6 @@ files:
|
|
99
97
|
- app/controllers/devise_token_auth/passwords_controller.rb
|
100
98
|
- app/controllers/devise_token_auth/registrations_controller.rb
|
101
99
|
- app/controllers/devise_token_auth/sessions_controller.rb
|
102
|
-
- app/helpers/devise_token_auth/application_helper.rb
|
103
100
|
- app/models/devise_token_auth/concerns/user.rb
|
104
101
|
- app/views/devise/mailer/confirmation_instructions.html.erb
|
105
102
|
- app/views/devise/mailer/reset_password_instructions.html.erb
|
@@ -176,6 +173,9 @@ files:
|
|
176
173
|
- test/dummy/public/422.html
|
177
174
|
- test/dummy/public/500.html
|
178
175
|
- test/dummy/public/favicon.ico
|
176
|
+
- test/dummy/tmp/generators/app/models/user.rb
|
177
|
+
- test/dummy/tmp/generators/config/initializers/devise_token_auth.rb
|
178
|
+
- test/dummy/tmp/generators/db/migrate/20140721004743_devise_token_auth_create_users.rb
|
179
179
|
- test/dummy/tmp/restart.txt
|
180
180
|
- test/fixtures/mangs.yml
|
181
181
|
- test/fixtures/users.yml
|
@@ -205,7 +205,7 @@ rubyforge_project:
|
|
205
205
|
rubygems_version: 2.2.2
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
|
-
summary: Token based authentication for rails. Uses
|
208
|
+
summary: Token based authentication for rails. Uses Devise + OmniAuth.
|
209
209
|
test_files:
|
210
210
|
- test/controllers/demo_controller_test.rb
|
211
211
|
- test/controllers/devise_token_auth/auth_controller_test.rb
|
@@ -263,6 +263,9 @@ test_files:
|
|
263
263
|
- test/dummy/public/favicon.ico
|
264
264
|
- test/dummy/Rakefile
|
265
265
|
- test/dummy/README.rdoc
|
266
|
+
- test/dummy/tmp/generators/app/models/user.rb
|
267
|
+
- test/dummy/tmp/generators/config/initializers/devise_token_auth.rb
|
268
|
+
- test/dummy/tmp/generators/db/migrate/20140721004743_devise_token_auth_create_users.rb
|
266
269
|
- test/dummy/tmp/restart.txt
|
267
270
|
- test/fixtures/mangs.yml
|
268
271
|
- test/fixtures/users.yml
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|