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 +4 -4
- data/README.md +32 -18
- data/app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb +13 -0
- data/app/mailers/rails_jwt_auth/mailer.rb +6 -0
- data/app/models/concerns/rails_jwt_auth/confirmable.rb +5 -0
- data/app/views/rails_jwt_auth/mailer/email_changed.html.erb +3 -0
- data/config/locales/en.yml +2 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- data/lib/rails_jwt_auth.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c7fdf2a0ecc3b2b48adc80426f802e411a7d315ad3d502d54591ba7978abd1
|
4
|
+
data.tar.gz: b7224f3281c49cb6c40ab28156c296a9cb74b3eefb68ac932940a931aa2886be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
48
|
-
|
|
49
|
-
| model_name
|
50
|
-
| auth_field_name
|
51
|
-
| email_auth_field
|
52
|
-
| jwt_expiration_time
|
53
|
-
| jwt_issuer
|
54
|
-
| simultaneous_sessions
|
55
|
-
| mailer_sender
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
data/config/locales/en.yml
CHANGED
data/lib/rails_jwt_auth.rb
CHANGED
@@ -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.
|
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-
|
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.
|
116
|
+
rubygems_version: 2.7.6
|
116
117
|
signing_key:
|
117
118
|
specification_version: 4
|
118
119
|
summary: Rails jwt authentication.
|