devise_jwt_auth 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7477d1f078d762ffca1b359a0b487d33816238f9cde0567a9e35731eb323b65e
4
- data.tar.gz: ebed2ca767f26b34ccae1cde42ec8c62352f3cbb14a11e2f3f6c2566217b0ee5
3
+ metadata.gz: a15d74ac0fd5ea01fed0ef24dd71dd28f04391a2467598be4a6738a2f19ca0df
4
+ data.tar.gz: 527bb191cbf4bf2baf1bdf56fa3e3308da17c012f3dcf8c391d7db47c3903816
5
5
  SHA512:
6
- metadata.gz: eb35296a86e539a9464bb086a7a2c25802a258f5e9de9f9b9eb177d93f2d0fac20767eed1115a9b9910c67a1e2f806ca16a7cd334356b1e74653ad19015164c5
7
- data.tar.gz: df54db926c3e38c54fcf46f284491f13e8b4f5c1be052aebbb2d2ce007139749a67b6c1e91104f39ca6f95c90f355fa168bb32a2879d0c9d83e727b199fe6d6d
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeviseJwtAuth
4
- VERSION = '0.1.4'.freeze
4
+ VERSION = '0.1.5'.freeze
5
5
  end
@@ -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
- create_table(:<%= table_name %><%= primary_key_type %>) do |t|
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, :trackable, :validatable
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 not have refresh token' do
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 Azpire::V1::HumanResource::User < ActiveRecord::Base
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, :trackable, :validatable
7
+ :recoverable, :rememberable, :validatable
8
8
  include DeviseJwtAuth::Concerns::User
9
9
  end
@@ -0,0 +1,9 @@
1
+ Rails.application.routes.draw do
2
+ mount_devise_jwt_auth_for 'User', at: 'auth'
3
+
4
+ mount_devise_jwt_auth_for 'Mang', at: 'mangs'
5
+ as :mang do
6
+ # Define routes for Mang within this block.
7
+ end
8
+ patch '/chong', to: 'bong#index'
9
+ end
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class DeviseJwtAuthCreateAzpireV1HumanResourceUsers < ActiveRecord::Migration[6.0]
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 :azpire_v1_human_resource_users, :email, unique: true
46
- add_index :azpire_v1_human_resource_users, [:uid, :provider], unique: true
47
- add_index :azpire_v1_human_resource_users, :reset_password_token, unique: true
48
- add_index :azpire_v1_human_resource_users, :confirmation_token, unique: true
49
- # add_index :azpire_v1_human_resource_users, :unlock_token, unique: true
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
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-10 00:00:00.000000000 Z
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/azpire/v1/human_resource/user.rb
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/db/migrate/20200210193225_devise_jwt_auth_create_azpire_v1_human_resource_users.rb
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/20200210193225_devise_jwt_auth_create_azpire_v1_human_resource_users.rb
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/azpire/v1/human_resource/user.rb
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