devise_jwt_auth 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/devise_jwt_auth/concerns/set_user_by_token.rb +7 -1
- data/app/controllers/devise_jwt_auth/sessions_controller.rb +3 -9
- data/lib/devise_jwt_auth/version.rb +1 -1
- data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +14 -0
- data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth_create_users.rb.erb +15 -11
- data/lib/generators/devise_jwt_auth/templates/user.rb.erb +2 -2
- data/test/controllers/devise_jwt_auth/sessions_controller_test.rb +2 -2
- data/test/dummy/tmp/generators/app/models/mang.rb +9 -0
- data/test/dummy/tmp/generators/app/models/{azpire/v1/human_resource/user.rb → user.rb} +3 -3
- data/test/dummy/tmp/generators/config/routes.rb +9 -0
- data/test/dummy/tmp/generators/db/migrate/{20200210193225_devise_jwt_auth_create_azpire_v1_human_resource_users.rb → 20200228012905_devise_jwt_auth_create_mangs.rb} +20 -17
- data/test/dummy/tmp/generators/db/migrate/20200228012905_devise_jwt_auth_create_users.rb +54 -0
- metadata +12 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a15d74ac0fd5ea01fed0ef24dd71dd28f04391a2467598be4a6738a2f19ca0df
|
4
|
+
data.tar.gz: 527bb191cbf4bf2baf1bdf56fa3e3308da17c012f3dcf8c391d7db47c3903816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6332f906fd89b8938de3a6c16916805802ac5d04b71e7ef8e437ff00b69b6f12101d929aec8271306029047abaed0de6fa4be061abd13425a019efa1f3aee793
|
7
|
+
data.tar.gz: 4d26f6f3c681ec83d5d0b518d4def8afab6a6c587dbffbbf37ffd690c75c06a7497d3c89f0a217f6a3fcf9545dcb19520b3832fb77e36fe8b1524a627f2179ce
|
@@ -107,5 +107,11 @@ module DeviseJwtAuth::Concerns::SetUserByToken
|
|
107
107
|
)
|
108
108
|
end
|
109
109
|
|
110
|
-
|
110
|
+
def clear_refresh_token_cookie
|
111
|
+
response.set_cookie(DeviseJwtAuth.refresh_token_name,
|
112
|
+
value: '',
|
113
|
+
path: '/auth/refresh_token', # TODO: Use configured auth path
|
114
|
+
expires: Time.zone.now
|
115
|
+
)
|
116
|
+
end
|
111
117
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# see http://www.emilsoman.com/blog/2013/05/18/building-a-tested/
|
4
3
|
module DeviseJwtAuth
|
5
4
|
class SessionsController < DeviseJwtAuth::ApplicationController
|
6
5
|
before_action :set_user_by_token, only: [:destroy]
|
@@ -48,18 +47,13 @@ module DeviseJwtAuth
|
|
48
47
|
|
49
48
|
def destroy
|
50
49
|
# TODO: logout? update token version?
|
51
|
-
|
50
|
+
|
52
51
|
# remove auth instance variables so that after_action does not run
|
53
52
|
user = remove_instance_variable(:@resource) if @resource
|
54
|
-
# client = @token.client if @token.client
|
55
|
-
# @token.clear!
|
56
|
-
|
57
|
-
if user # && client && user.tokens[client]
|
58
|
-
# user.tokens.delete(client)
|
59
|
-
# user.save!
|
60
53
|
|
54
|
+
if user
|
61
55
|
yield user if block_given?
|
62
|
-
|
56
|
+
clear_refresh_token_cookie
|
63
57
|
render_destroy_success
|
64
58
|
else
|
65
59
|
render_destroy_error
|
@@ -67,6 +67,20 @@ module DeviseJwtAuth
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def ip_column
|
71
|
+
# Padded with spaces so it aligns nicely with the rest of the columns.
|
72
|
+
"%-8s" % (inet? ? "inet" : "string")
|
73
|
+
end
|
74
|
+
|
75
|
+
def inet?
|
76
|
+
postgresql?
|
77
|
+
end
|
78
|
+
|
79
|
+
def postgresql?
|
80
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
81
|
+
config && config['adapter'] == 'postgresql'
|
82
|
+
end
|
83
|
+
|
70
84
|
private
|
71
85
|
|
72
86
|
def insert_after_line(filename, line, str)
|
@@ -2,12 +2,18 @@
|
|
2
2
|
|
3
3
|
class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecord::Migration<%= "[#{Rails::VERSION::STRING[0..2]}]" if Rails::VERSION::MAJOR > 4 %>
|
4
4
|
def change
|
5
|
-
<% table_name = @user_class.pluralize.gsub("::","").underscore
|
6
|
-
|
5
|
+
<% table_name = @user_class.pluralize.gsub("::","").underscore -%>
|
6
|
+
create_table(:<%= table_name %><%= primary_key_type %>) do |t|
|
7
7
|
## Required
|
8
8
|
t.string :provider, null: false, default: 'email'
|
9
9
|
t.string :uid, null: false, default: ''
|
10
10
|
|
11
|
+
## User Info
|
12
|
+
t.string :name
|
13
|
+
t.string :nickname
|
14
|
+
t.string :image
|
15
|
+
t.string :email
|
16
|
+
|
11
17
|
## Database authenticatable
|
12
18
|
t.string :encrypted_password, null: false, default: ''
|
13
19
|
|
@@ -19,6 +25,13 @@ class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecor
|
|
19
25
|
## Rememberable
|
20
26
|
t.datetime :remember_created_at
|
21
27
|
|
28
|
+
## Trackable
|
29
|
+
# t.integer :sign_in_count, default: 0, null: false
|
30
|
+
# t.datetime :current_sign_in_at
|
31
|
+
# t.datetime :last_sign_in_at
|
32
|
+
# t.<%= ip_column %> :current_sign_in_ip
|
33
|
+
# t.<%= ip_column %> :last_sign_in_ip
|
34
|
+
|
22
35
|
## Confirmable
|
23
36
|
t.string :confirmation_token
|
24
37
|
t.datetime :confirmed_at
|
@@ -30,15 +43,6 @@ class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecor
|
|
30
43
|
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
31
44
|
# t.datetime :locked_at
|
32
45
|
|
33
|
-
## User Info
|
34
|
-
t.string :name
|
35
|
-
t.string :nickname
|
36
|
-
t.string :image
|
37
|
-
t.string :email
|
38
|
-
|
39
|
-
## Tokens
|
40
|
-
<%= json_supported_database? ? 't.json :tokens' : 't.text :tokens' %>
|
41
|
-
|
42
46
|
t.timestamps
|
43
47
|
end
|
44
48
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
class <%= user_class %> < ActiveRecord::Base
|
4
4
|
# Include default devise modules. Others available are:
|
5
|
-
# :confirmable, :lockable, :timeoutable and :omniauthable
|
5
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
6
6
|
devise :database_authenticatable, :registerable,
|
7
|
-
:recoverable, :rememberable, :
|
7
|
+
:recoverable, :rememberable, :validatable
|
8
8
|
include DeviseJwtAuth::Concerns::User
|
9
9
|
end
|
@@ -141,7 +141,8 @@ class DeviseJwtAuth::SessionsControllerTest < ActionController::TestCase
|
|
141
141
|
assert_nil @data[DeviseJwtAuth.access_token_name]
|
142
142
|
end
|
143
143
|
|
144
|
-
test 'response should
|
144
|
+
test 'response should delete refresh token from client' do
|
145
|
+
assert_equal true, response.cookies.keys.include?(DeviseJwtAuth.refresh_token_name)
|
145
146
|
assert_nil response.cookies[DeviseJwtAuth.refresh_token_name]
|
146
147
|
end
|
147
148
|
|
@@ -284,7 +285,6 @@ class DeviseJwtAuth::SessionsControllerTest < ActionController::TestCase
|
|
284
285
|
@data = JSON.parse(response.body)
|
285
286
|
|
286
287
|
assert_equal 200, response.status
|
287
|
-
# p 'DATA', @data.inspect
|
288
288
|
assert @data[DeviseJwtAuth.access_token_name]
|
289
289
|
assert response.cookies[DeviseJwtAuth.refresh_token_name]
|
290
290
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Mang < ActiveRecord::Base
|
4
|
+
# Include default devise modules. Others available are:
|
5
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
6
|
+
devise :database_authenticatable, :registerable,
|
7
|
+
:recoverable, :rememberable, :validatable
|
8
|
+
include DeviseJwtAuth::Concerns::User
|
9
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class
|
3
|
+
class User < ActiveRecord::Base
|
4
4
|
# Include default devise modules. Others available are:
|
5
|
-
# :confirmable, :lockable, :timeoutable and :omniauthable
|
5
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
6
6
|
devise :database_authenticatable, :registerable,
|
7
|
-
:recoverable, :rememberable, :
|
7
|
+
:recoverable, :rememberable, :validatable
|
8
8
|
include DeviseJwtAuth::Concerns::User
|
9
9
|
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class
|
3
|
+
class DeviseJwtAuthCreateMangs < ActiveRecord::Migration[6.0]
|
4
4
|
def change
|
5
|
-
|
6
|
-
create_table(:azpire_v1_human_resource_users) do |t|
|
5
|
+
create_table(:mangs) do |t|
|
7
6
|
## Required
|
8
7
|
t.string :provider, null: false, default: 'email'
|
9
8
|
t.string :uid, null: false, default: ''
|
10
9
|
|
10
|
+
## User Info
|
11
|
+
t.string :name
|
12
|
+
t.string :nickname
|
13
|
+
t.string :image
|
14
|
+
t.string :email
|
15
|
+
|
11
16
|
## Database authenticatable
|
12
17
|
t.string :encrypted_password, null: false, default: ''
|
13
18
|
|
@@ -19,6 +24,13 @@ class DeviseJwtAuthCreateAzpireV1HumanResourceUsers < ActiveRecord::Migration[6.
|
|
19
24
|
## Rememberable
|
20
25
|
t.datetime :remember_created_at
|
21
26
|
|
27
|
+
## Trackable
|
28
|
+
# t.integer :sign_in_count, default: 0, null: false
|
29
|
+
# t.datetime :current_sign_in_at
|
30
|
+
# t.datetime :last_sign_in_at
|
31
|
+
# t.string :current_sign_in_ip
|
32
|
+
# t.string :last_sign_in_ip
|
33
|
+
|
22
34
|
## Confirmable
|
23
35
|
t.string :confirmation_token
|
24
36
|
t.datetime :confirmed_at
|
@@ -30,22 +42,13 @@ class DeviseJwtAuthCreateAzpireV1HumanResourceUsers < ActiveRecord::Migration[6.
|
|
30
42
|
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
31
43
|
# t.datetime :locked_at
|
32
44
|
|
33
|
-
## User Info
|
34
|
-
t.string :name
|
35
|
-
t.string :nickname
|
36
|
-
t.string :image
|
37
|
-
t.string :email
|
38
|
-
|
39
|
-
## Tokens
|
40
|
-
t.text :tokens
|
41
|
-
|
42
45
|
t.timestamps
|
43
46
|
end
|
44
47
|
|
45
|
-
add_index :
|
46
|
-
add_index :
|
47
|
-
add_index :
|
48
|
-
add_index :
|
49
|
-
# add_index :
|
48
|
+
add_index :mangs, :email, unique: true
|
49
|
+
add_index :mangs, [:uid, :provider], unique: true
|
50
|
+
add_index :mangs, :reset_password_token, unique: true
|
51
|
+
add_index :mangs, :confirmation_token, unique: true
|
52
|
+
# add_index :mangs, :unlock_token, unique: true
|
50
53
|
end
|
51
54
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DeviseJwtAuthCreateUsers < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
create_table(:users) do |t|
|
6
|
+
## Required
|
7
|
+
t.string :provider, null: false, default: 'email'
|
8
|
+
t.string :uid, null: false, default: ''
|
9
|
+
|
10
|
+
## User Info
|
11
|
+
t.string :name
|
12
|
+
t.string :nickname
|
13
|
+
t.string :image
|
14
|
+
t.string :email
|
15
|
+
|
16
|
+
## Database authenticatable
|
17
|
+
t.string :encrypted_password, null: false, default: ''
|
18
|
+
|
19
|
+
## Recoverable
|
20
|
+
t.string :reset_password_token
|
21
|
+
t.datetime :reset_password_sent_at
|
22
|
+
t.boolean :allow_password_change, default: false
|
23
|
+
|
24
|
+
## Rememberable
|
25
|
+
t.datetime :remember_created_at
|
26
|
+
|
27
|
+
## Trackable
|
28
|
+
# t.integer :sign_in_count, default: 0, null: false
|
29
|
+
# t.datetime :current_sign_in_at
|
30
|
+
# t.datetime :last_sign_in_at
|
31
|
+
# t.string :current_sign_in_ip
|
32
|
+
# t.string :last_sign_in_ip
|
33
|
+
|
34
|
+
## Confirmable
|
35
|
+
t.string :confirmation_token
|
36
|
+
t.datetime :confirmed_at
|
37
|
+
t.datetime :confirmation_sent_at
|
38
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
39
|
+
|
40
|
+
## Lockable
|
41
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
42
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
43
|
+
# t.datetime :locked_at
|
44
|
+
|
45
|
+
t.timestamps
|
46
|
+
end
|
47
|
+
|
48
|
+
add_index :users, :email, unique: true
|
49
|
+
add_index :users, [:uid, :provider], unique: true
|
50
|
+
add_index :users, :reset_password_token, unique: true
|
51
|
+
add_index :users, :confirmation_token, unique: true
|
52
|
+
# add_index :users, :unlock_token, unique: true
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron A
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -64,20 +64,6 @@ dependencies:
|
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '5'
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: bcrypt
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '3.0'
|
74
|
-
type: :runtime
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '3.0'
|
81
67
|
- !ruby/object:Gem::Dependency
|
82
68
|
name: jwt
|
83
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -348,9 +334,12 @@ files:
|
|
348
334
|
- test/dummy/db/migrate/20190924101113_devise_jwt_auth_create_confirmable_users.rb
|
349
335
|
- test/dummy/db/schema.rb
|
350
336
|
- test/dummy/lib/migration_database_helper.rb
|
351
|
-
- test/dummy/tmp/generators/app/models/
|
337
|
+
- test/dummy/tmp/generators/app/models/mang.rb
|
338
|
+
- test/dummy/tmp/generators/app/models/user.rb
|
352
339
|
- test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb
|
353
|
-
- test/dummy/tmp/generators/
|
340
|
+
- test/dummy/tmp/generators/config/routes.rb
|
341
|
+
- test/dummy/tmp/generators/db/migrate/20200228012905_devise_jwt_auth_create_mangs.rb
|
342
|
+
- test/dummy/tmp/generators/db/migrate/20200228012905_devise_jwt_auth_create_users.rb
|
354
343
|
- test/factories/users.rb
|
355
344
|
- test/lib/devise_jwt_auth/blacklist_test.rb
|
356
345
|
- test/lib/devise_jwt_auth/token_factory_test.rb
|
@@ -405,9 +394,12 @@ test_files:
|
|
405
394
|
- test/test_helper.rb
|
406
395
|
- test/dummy/lib/migration_database_helper.rb
|
407
396
|
- test/dummy/config.ru
|
408
|
-
- test/dummy/tmp/generators/db/migrate/
|
397
|
+
- test/dummy/tmp/generators/db/migrate/20200228012905_devise_jwt_auth_create_users.rb
|
398
|
+
- test/dummy/tmp/generators/db/migrate/20200228012905_devise_jwt_auth_create_mangs.rb
|
399
|
+
- test/dummy/tmp/generators/config/routes.rb
|
409
400
|
- test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb
|
410
|
-
- test/dummy/tmp/generators/app/models/
|
401
|
+
- test/dummy/tmp/generators/app/models/mang.rb
|
402
|
+
- test/dummy/tmp/generators/app/models/user.rb
|
411
403
|
- test/dummy/db/migrate/20150708104536_devise_jwt_auth_create_unconfirmable_users.rb
|
412
404
|
- test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb
|
413
405
|
- test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb
|