rails_jwt_auth 1.2.0 → 1.3.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: 4023162adcfa3953a4b917b533a4531141ce70b30c45b1502fc47e360a58d8f6
4
- data.tar.gz: d95f7deaa3e194114cc21cd6354a1f4fcede72a6f307de7abf210fcf9493f9f2
3
+ metadata.gz: 29c7fdf2a0ecc3b2b48adc80426f802e411a7d315ad3d502d54591ba7978abd1
4
+ data.tar.gz: b7224f3281c49cb6c40ab28156c296a9cb74b3eefb68ac932940a931aa2886be
5
5
  SHA512:
6
- metadata.gz: 05b4fa9c7fb11772014e015dd266ba5e3e99f3d0eb17970cbafefe941635e3eb2ef0d4bdfa696e4c0cd4798f1c6bdbe83610fda784a77ac2a45def7bcc1c63b4
7
- data.tar.gz: 938906e3edee4d5647168f0953b5127a810d95776e841f172da4854e17926595d1d9f9d611a74d5f1c3d4b24d78d8ee37fcaf36c48703b491d94a7ea4fc2db88
6
+ metadata.gz: e208d2d4fc4a900a584a03d718b8539f0f53717d2bbeb15189d125d6f235e135c6e8d7de77df60cf128611cf512b8380fa747c604572495eebca32abff8d26f6
7
+ data.tar.gz: ab21acd7f88451742875b62f131c86243c715cc3c942ba94b7d6782c266800b68c35aef5b524c86e5bbbdbd2c9943f286d09e62d59a03562fdc667f4aae5dbd6
data/README.md CHANGED
@@ -44,23 +44,24 @@ rails g rails_jwt_auth:migrate
44
44
 
45
45
  You can edit configuration options into `config/initializers/auth_token_auth.rb` file created by generator.
46
46
 
47
- | Option | Default value | Description |
48
- | ------------------------------ | ----------------- | ---------------------------------------------------------------------- |
49
- | model_name | 'User' | Authentication model name |
50
- | auth_field_name | 'email' | Field used to authenticate user with password |
51
- | email_auth_field | 'email' | Field used to send emails |
52
- | jwt_expiration_time | 7.days | Tokens expiration time |
53
- | jwt_issuer | 'RailsJwtAuth' | The "iss" (issuer) claim identifies the principal that issued the JWT |
54
- | simultaneous_sessions | 2 | Number of simultaneous sessions for an user. Set 0 to disable sessions |
55
- | mailer_sender | | E-mail address which will be shown in RailsJwtAuth::Mailer |
56
- | confirmation_expiration_time | 1.day | Confirmation token expiration time |
57
- | reset_password_expiration_time | 1.day | Confirmation token expiration time |
58
- | deliver_later | false | Uses `deliver_later` method to send emails |
59
- | invitation_expiration_time | 2.days | Time an invitation is valid and can be accepted |
60
- | confirmations_url | nil | Url used to create email link with confirmation token |
61
- | reset_passwords_url | nil | Url used to create email link with reset password token |
62
- | set_passwords_url | nil | Url used to create email link with set password token |
63
- | invitationss_url | nil | Url used to create email link with invitation token |
47
+ | Option | Default value | Description |
48
+ | ------------------------------- | ----------------- | ---------------------------------------------------------------------- |
49
+ | model_name | 'User' | Authentication model name |
50
+ | auth_field_name | 'email' | Field used to authenticate user with password |
51
+ | email_auth_field | 'email' | Field used to send emails |
52
+ | jwt_expiration_time | 7.days | Tokens expiration time |
53
+ | jwt_issuer | 'RailsJwtAuth' | The "iss" (issuer) claim identifies the principal that issued the JWT |
54
+ | simultaneous_sessions | 2 | Number of simultaneous sessions for an user. Set 0 to disable sessions |
55
+ | mailer_sender | | E-mail address which will be shown in RailsJwtAuth::Mailer |
56
+ | send_email_changed_notification | true | Notify original email when it changes |
57
+ | confirmation_expiration_time | 1.day | Confirmation token expiration time |
58
+ | reset_password_expiration_time | 1.day | Confirmation token expiration time |
59
+ | deliver_later | false | Uses `deliver_later` method to send emails |
60
+ | invitation_expiration_time | 2.days | Time an invitation is valid and can be accepted |
61
+ | confirmations_url | nil | Url used to create email link with confirmation token |
62
+ | reset_passwords_url | nil | Url used to create email link with reset password token |
63
+ | set_passwords_url | nil | Url used to create email link with set password token |
64
+ | invitationss_url | nil | Url used to create email link with invitation token |
64
65
 
65
66
  ## Modules
66
67
 
@@ -137,7 +138,20 @@ end
137
138
  end
138
139
  ```
139
140
 
140
- This helper expect that token has been into **AUTHORIZATION** header.
141
+ This helper expect that token has been into **AUTHORIZATION** header.
142
+ Raises `RailsJwtAuth::NotAuthorized` exception when it fails.
143
+
144
+ - **authenticate**
145
+
146
+ Authenticate your controllers:
147
+
148
+ ```ruby
149
+ class MyController < ApplicationController
150
+ before_action :authenticate
151
+ end
152
+ ```
153
+
154
+ This helper is like `authenticate!` but it not raises exception
141
155
 
142
156
  - **current_user**
143
157
 
@@ -24,6 +24,19 @@ module RailsJwtAuth
24
24
  end
25
25
  end
26
26
 
27
+ def authenticate
28
+ begin
29
+ payload = RailsJwtAuth::JwtManager.decode_from_request(request).first
30
+ @current_user = RailsJwtAuth.model.from_token_payload(payload)
31
+ rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError
32
+ @current_user = nil
33
+ end
34
+
35
+ if @current_user&.respond_to? :update_tracked_fields!
36
+ @current_user.update_tracked_fields!(request)
37
+ end
38
+ end
39
+
27
40
  def unauthorize!
28
41
  raise NotAuthorized
29
42
  end
@@ -15,6 +15,12 @@ if defined?(ActionMailer)
15
15
  mail(to: @user.unconfirmed_email || @user[RailsJwtAuth.email_field_name], subject: subject)
16
16
  end
17
17
 
18
+ def email_changed(user)
19
+ @user = user
20
+ subject = I18n.t('rails_jwt_auth.mailer.email_changed.subject')
21
+ mail(to: @user[RailsJwtAuth.email_field_name!], subject: subject)
22
+ end
23
+
18
24
  def reset_password_instructions(user)
19
25
  raise RailsJwtAuth::NotResetPasswordsUrl unless RailsJwtAuth.reset_passwords_url.present?
20
26
  @user = user
@@ -36,6 +36,11 @@ module RailsJwtAuth
36
36
 
37
37
  mailer = Mailer.confirmation_instructions(self)
38
38
  RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
39
+
40
+ if RailsJwtAuth.send_email_changed_notification
41
+ mailer = Mailer.email_changed(self)
42
+ RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
43
+ end
39
44
  end
40
45
  end
41
46
  end
@@ -0,0 +1,3 @@
1
+ <p>Hello <%= @user[RailsJwtAuth.email_field_name] %>!</p>
2
+
3
+ <p>We're contacting you to notify you that your email is being changed to <%= @user.unconfirmed_email %>.</p>
@@ -9,3 +9,5 @@ en:
9
9
  subject: "Set password instructions"
10
10
  send_invitation:
11
11
  subject: "Someone has sent you an invitation!"
12
+ email_changed:
13
+ subject: "Email changed"
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -32,6 +32,9 @@ module RailsJwtAuth
32
32
  mattr_accessor :mailer_sender
33
33
  self.mailer_sender = 'initialize-mailer_sender@example.com'
34
34
 
35
+ mattr_accessor :send_email_changed_notification
36
+ self.send_email_changed_notification = true
37
+
35
38
  mattr_accessor :confirmation_expiration_time
36
39
  self.confirmation_expiration_time = 1.day
37
40
 
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: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -79,6 +79,7 @@ files:
79
79
  - app/models/concerns/rails_jwt_auth/recoverable.rb
80
80
  - app/models/concerns/rails_jwt_auth/trackable.rb
81
81
  - app/views/rails_jwt_auth/mailer/confirmation_instructions.html.erb
82
+ - app/views/rails_jwt_auth/mailer/email_changed.html.erb
82
83
  - app/views/rails_jwt_auth/mailer/reset_password_instructions.html.erb
83
84
  - app/views/rails_jwt_auth/mailer/send_invitation.html.erb
84
85
  - app/views/rails_jwt_auth/mailer/set_password_instructions.html.erb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  requirements: []
114
115
  rubyforge_project:
115
- rubygems_version: 2.7.3
116
+ rubygems_version: 2.7.6
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: Rails jwt authentication.