rails_jwt_auth 0.19.3 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81123645fdb879ac69e750a8d8efe5bd6e2cedf2c8cd500c7563da43effbd0c2
4
- data.tar.gz: 23525800b9fcc916e94e10472c1d5efe447b1526452aa2e60f333613b5b25c7e
3
+ metadata.gz: 7a7954b3c32181adbad0fc1353f87503eb3c1a9da366aa57019121249bb0d859
4
+ data.tar.gz: dc7d92d0ad939cfc508284986ad11671abe6d8ec1d8ec8476d4ec1d1b9d99468
5
5
  SHA512:
6
- metadata.gz: 5434fee2a0065f80423ff6fe27ac02333d0aed899c6e43c2d1623b5bd480b789c77da8b43883e80c23169b61e7c63b7f40bc8b52d39c2c12c79f43008514e727
7
- data.tar.gz: 3e9e3f3cb2337d6b29934c9f8f920dba68167c2f95c24287b879266058f474426846cc33d69a848d9c70d68f643c2810171a11178f4c081c020969b6cb431ec5
6
+ metadata.gz: 4d8b93466166a0ecee271dcce19b0bcdfba81006d50f05253120cb8b2605f8c7c35407c994352c2cb7829801e01a297778d01610c3fb32a04e43c71cc17d30cd
7
+ data.tar.gz: 1ae8ee7ec75ac8685e64a5662d3372cca533f4a78088fa1ce4d9a1bd0109652e02c88ddb4341238bd3be8d20d65f8401a3e2ea0c5c05b01a09ce99634abcc617
data/README.md CHANGED
@@ -453,17 +453,21 @@ Note: To add more fields, see "Custom strong parameters" below.
453
453
  You can overwrite RailsJwtAuth controllers to edit actions, responses,
454
454
  permitted parameters...
455
455
 
456
- For example, if we want to change registration strong parameters we
456
+ For example, if we want to call custom method when user is created we need to
457
457
  create new registration controller inherited from default controller:
458
458
 
459
459
  ```ruby
460
460
  # app/controllers/registrations_controller.rb
461
461
  class RegistrationsController < RailsJwtAuth::RegistrationsController
462
- private
462
+ ...
463
463
 
464
- def create_params
465
- params.require(:user).permit(:email, :name, :surname, :password, :password_confirmation)
464
+ def create
465
+ user = RailsJwtAuth.model.new(create_params)
466
+ user.do_something_custom
467
+ ...
466
468
  end
469
+
470
+ ...
467
471
  end
468
472
  ```
469
473
 
@@ -474,6 +478,32 @@ And edit route resource to use it:
474
478
  resource :registration, controller: 'registrations', only: [:create, :update, :destroy]
475
479
  ```
476
480
 
481
+ ## Custom payload
482
+
483
+ If you need edit default payload used to generate jwt you can overwrite the method `to_token_payload` into your User class:
484
+
485
+ ```ruby
486
+ class User < ApplicationRecord
487
+ include RailsJwtAuth::Authenticatable
488
+ ...
489
+
490
+ def to_token_payload(request)
491
+ {
492
+ auth_token: regenerate_auth_token,
493
+ # add here your custom info
494
+ }
495
+ end
496
+ end
497
+ ```
498
+
499
+ ## Custom responses
500
+
501
+ You can overwrite `RailsJwtAuth::RenderHelper` to customize controllers responses.
502
+
503
+ ## Custom strong parameters
504
+
505
+ You can overwrite `RailsJwtAuth::ParamsHelper` to customize controllers strong parameters.
506
+
477
507
  ## Edit user information
478
508
 
479
509
  This is a controller example that allows users to edit their `email` and `password`.
@@ -520,14 +550,6 @@ class UsersController < ApplicationController
520
550
  end
521
551
  ```
522
552
 
523
- ## Custom responses
524
-
525
- You can overwrite `RailsJwtAuth::RenderHelper` to customize controllers responses.
526
-
527
- ## Custom strong parameters
528
-
529
- You can overwrite `RailsJwtAuth::ParamsHelper` to customize controllers strong parameters.
530
-
531
553
  ## Testing (rspec)
532
554
 
533
555
  Require the RailsJwtAuth::Spec::Helpers helper module in `rails_helper.rb`.
@@ -30,8 +30,7 @@ module RailsJwtAuth
30
30
  private
31
31
 
32
32
  def get_jwt(user)
33
- token = user.regenerate_auth_token
34
- RailsJwtAuth::Jwt::Manager.encode(auth_token: token)
33
+ RailsJwtAuth::Jwt::Manager.encode(user.to_token_payload(request))
35
34
  end
36
35
 
37
36
  def create_session_error
@@ -38,6 +38,10 @@ module RailsJwtAuth
38
38
  errors.empty? ? update_attributes(params) : false
39
39
  end
40
40
 
41
+ def to_token_payload(_request)
42
+ {auth_token: regenerate_auth_token}
43
+ end
44
+
41
45
  module ClassMethods
42
46
  def get_by_token(token)
43
47
  if defined?(Mongoid) && ancestors.include?(Mongoid::Document)
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '0.19.3'
2
+ VERSION = '0.20.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.3
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-26 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails