rails_jwt_auth 0.18.1 → 1.3.1
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 +5 -5
- data/README.md +161 -242
- data/app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb +44 -0
- data/app/controllers/concerns/rails_jwt_auth/params_helper.rb +1 -3
- data/app/controllers/concerns/rails_jwt_auth/render_helper.rb +4 -0
- data/app/controllers/rails_jwt_auth/confirmations_controller.rb +6 -9
- data/app/controllers/rails_jwt_auth/invitations_controller.rb +8 -9
- data/app/controllers/rails_jwt_auth/passwords_controller.rb +8 -16
- data/app/controllers/rails_jwt_auth/registrations_controller.rb +1 -1
- data/app/controllers/rails_jwt_auth/sessions_controller.rb +14 -15
- data/app/mailers/rails_jwt_auth/mailer.rb +30 -39
- data/app/models/concerns/rails_jwt_auth/authenticatable.rb +44 -32
- data/app/models/concerns/rails_jwt_auth/confirmable.rb +59 -47
- data/app/models/concerns/rails_jwt_auth/invitable.rb +36 -34
- data/app/models/concerns/rails_jwt_auth/recoverable.rb +28 -27
- data/app/models/concerns/rails_jwt_auth/trackable.rb +1 -1
- data/app/views/rails_jwt_auth/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/rails_jwt_auth/mailer/email_changed.html.erb +3 -0
- data/app/views/rails_jwt_auth/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/rails_jwt_auth/mailer/send_invitation.html.erb +2 -2
- data/app/views/rails_jwt_auth/mailer/set_password_instructions.html.erb +2 -2
- data/config/locales/en.yml +2 -17
- data/lib/generators/rails_jwt_auth/install_generator.rb +6 -7
- data/lib/generators/rails_jwt_auth/migrate_generator.rb +17 -0
- data/lib/generators/templates/initializer.rb +17 -21
- data/lib/generators/templates/migration.rb +29 -0
- data/lib/rails_jwt_auth/engine.rb +0 -21
- data/lib/rails_jwt_auth/jwt_manager.rb +33 -0
- data/lib/rails_jwt_auth/spec_helpers.rb +19 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- data/lib/rails_jwt_auth.rb +67 -30
- metadata +25 -35
- data/app/controllers/concerns/rails_jwt_auth/warden_helper.rb +0 -27
- data/app/validators/email_validator.rb +0 -7
- data/lib/rails_jwt_auth/jwt/manager.rb +0 -37
- data/lib/rails_jwt_auth/jwt/request.rb +0 -34
- data/lib/rails_jwt_auth/spec/helpers.rb +0 -17
- data/lib/rails_jwt_auth/spec/not_authorized.rb +0 -6
- data/lib/rails_jwt_auth/strategies/jwt.rb +0 -17
- data/lib/tasks/rails_token_jwt_tasks.rake +0 -4
@@ -1,13 +1,34 @@
|
|
1
1
|
module RailsJwtAuth
|
2
2
|
module Recoverable
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
if defined?(Mongoid) && base.ancestors.include?(Mongoid::Document)
|
6
|
+
# include GlobalID::Identification to use deliver_later method
|
7
|
+
# http://edgeguides.rubyonrails.org/active_job_basics.html#globalid
|
8
|
+
include GlobalID::Identification if RailsJwtAuth.deliver_later
|
9
|
+
|
10
|
+
field :reset_password_token, type: String
|
11
|
+
field :reset_password_sent_at, type: Time
|
12
|
+
end
|
13
|
+
|
14
|
+
validate :validate_reset_password_token, if: :password_digest_changed?
|
15
|
+
|
16
|
+
before_update do
|
17
|
+
self.reset_password_token = nil if password_digest_changed? && reset_password_token
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
3
22
|
def send_reset_password_instructions
|
23
|
+
email_field = RailsJwtAuth.email_field_name! # ensure email field es valid
|
24
|
+
|
4
25
|
if self.class.ancestors.include?(RailsJwtAuth::Confirmable) && !confirmed?
|
5
|
-
errors.add(
|
26
|
+
errors.add(email_field, :unconfirmed)
|
6
27
|
return false
|
7
28
|
end
|
8
29
|
|
9
30
|
self.reset_password_token = SecureRandom.base58(24)
|
10
|
-
self.reset_password_sent_at = Time.
|
31
|
+
self.reset_password_sent_at = Time.current
|
11
32
|
return false unless save
|
12
33
|
|
13
34
|
mailer = Mailer.reset_password_instructions(self)
|
@@ -15,6 +36,7 @@ module RailsJwtAuth
|
|
15
36
|
end
|
16
37
|
|
17
38
|
def set_and_send_password_instructions
|
39
|
+
RailsJwtAuth.email_field_name! # ensure email field es valid
|
18
40
|
return if password.present?
|
19
41
|
|
20
42
|
self.password = SecureRandom.base58(48)
|
@@ -22,7 +44,7 @@ module RailsJwtAuth
|
|
22
44
|
self.skip_confirmation! if self.class.ancestors.include?(RailsJwtAuth::Confirmable)
|
23
45
|
|
24
46
|
self.reset_password_token = SecureRandom.base58(24)
|
25
|
-
self.reset_password_sent_at = Time.
|
47
|
+
self.reset_password_sent_at = Time.current
|
26
48
|
return false unless save
|
27
49
|
|
28
50
|
mailer = Mailer.set_password_instructions(self)
|
@@ -30,33 +52,12 @@ module RailsJwtAuth
|
|
30
52
|
true
|
31
53
|
end
|
32
54
|
|
33
|
-
|
34
|
-
base.class_eval do
|
35
|
-
if base.ancestors.include? Mongoid::Document
|
36
|
-
# include GlobalID::Identification to use deliver_later method
|
37
|
-
# http://edgeguides.rubyonrails.org/active_job_basics.html#globalid
|
38
|
-
include GlobalID::Identification if RailsJwtAuth.deliver_later
|
39
|
-
|
40
|
-
field :reset_password_token, type: String
|
41
|
-
field :reset_password_sent_at, type: Time
|
42
|
-
end
|
43
|
-
|
44
|
-
validate :validate_reset_password_token, if: :password_digest_changed?
|
45
|
-
|
46
|
-
before_update do
|
47
|
-
if password_digest_changed? && reset_password_token
|
48
|
-
self.reset_password_token = nil
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
+
protected
|
55
56
|
|
56
57
|
def validate_reset_password_token
|
57
58
|
if reset_password_sent_at &&
|
58
|
-
(reset_password_sent_at < (Time.
|
59
|
-
errors.add(:reset_password_token,
|
59
|
+
(reset_password_sent_at < (Time.current - RailsJwtAuth.reset_password_expiration_time))
|
60
|
+
errors.add(:reset_password_token, :expired)
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RailsJwtAuth
|
2
2
|
module Trackable
|
3
3
|
def update_tracked_fields!(request)
|
4
|
-
self.last_sign_in_at = Time.
|
4
|
+
self.last_sign_in_at = Time.current
|
5
5
|
self.last_sign_in_ip = request.respond_to?(:remote_ip) ? request.remote_ip : request.ip
|
6
6
|
save(validate: false)
|
7
7
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<p>Welcome <%= @user.
|
1
|
+
<p>Welcome <%= @user[RailsJwtAuth.email_field_name] %>!</p>
|
2
2
|
|
3
3
|
<p>You can confirm your account email through the link below:</p>
|
4
4
|
|
5
|
-
<p><%= link_to 'Confirm my account', @
|
5
|
+
<p><%= link_to 'Confirm my account', @confirmations_url.html_safe %></p>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
<p>Hello <%= @user.
|
1
|
+
<p>Hello <%= @user[RailsJwtAuth.email_field_name] %>!</p>
|
2
2
|
|
3
3
|
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
|
4
4
|
|
5
|
-
<p><%= link_to 'Change my password', @
|
5
|
+
<p><%= link_to 'Change my password', @reset_passwords_url.html_safe %></p>
|
6
6
|
|
7
7
|
<p>If you didn't request this, please ignore this email.</p>
|
8
8
|
<p>Your password won't change until you access the link above and create a new one.</p>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<p>Hello <%= @user.
|
1
|
+
<p>Hello <%= @user[RailsJwtAuth.email_field_name] %>!</p>
|
2
2
|
|
3
3
|
<p>Someone has sent you an invitation to App.</p>
|
4
4
|
<p>To complete registration setting a password, please click the following link.</p>
|
5
5
|
|
6
|
-
<p><%= link_to "Accept invitation", @
|
6
|
+
<p><%= link_to "Accept invitation", @invitations_url.html_safe %></p>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<p>Hello <%= @user.
|
1
|
+
<p>Hello <%= @user[RailsJwtAuth.email_field_name] %>!</p>
|
2
2
|
|
3
3
|
<p>You need to define your password to complete registration. You can do this through the link below.</p>
|
4
4
|
|
5
|
-
<p><%= link_to 'Set my password', @
|
5
|
+
<p><%= link_to 'Set my password', @reset_passwords_url.html_safe %></p>
|
data/config/locales/en.yml
CHANGED
@@ -9,20 +9,5 @@ en:
|
|
9
9
|
subject: "Set password instructions"
|
10
10
|
send_invitation:
|
11
11
|
subject: "Someone has sent you an invitation!"
|
12
|
-
|
13
|
-
|
14
|
-
unconfirmed: "unconfirmed email"
|
15
|
-
already_confirmed: "was already confirmed, please try signing in"
|
16
|
-
create_session: "invalid %{field} / password"
|
17
|
-
expired: "has expired, please request a new one"
|
18
|
-
invalid: "invalid"
|
19
|
-
blank: "blank"
|
20
|
-
not_found: "not found"
|
21
|
-
missing: "is missing"
|
22
|
-
email:
|
23
|
-
invalid: "is not an email"
|
24
|
-
current_password:
|
25
|
-
blank: "blank"
|
26
|
-
invalid: "invalid"
|
27
|
-
password:
|
28
|
-
blank: "blank"
|
12
|
+
email_changed:
|
13
|
+
subject: "Email changed"
|
@@ -2,16 +2,15 @@ class RailsJwtAuth::InstallGenerator < Rails::Generators::Base
|
|
2
2
|
source_root File.expand_path('../../templates', __FILE__)
|
3
3
|
|
4
4
|
def create_initializer_file
|
5
|
-
copy_file
|
5
|
+
copy_file 'initializer.rb', 'config/initializers/rails_jwt_auth.rb'
|
6
6
|
end
|
7
7
|
|
8
8
|
def create_routes
|
9
|
-
route "
|
10
|
-
route "
|
9
|
+
route "resources :session, controller: 'rails_jwt_auth/sessions', only: [:create, :destroy]"
|
10
|
+
route "resources :registration, controller: 'rails_jwt_auth/registrations', only: [:create, :update, :destroy]"
|
11
11
|
|
12
|
-
route "
|
13
|
-
route "
|
14
|
-
|
15
|
-
route "resource :invitation, controller: 'rails_jwt_auth/invitations', only: [:create, :update]"
|
12
|
+
route "resources :confirmations, controller: 'rails_jwt_auth/confirmations', only: [:create, :update]"
|
13
|
+
route "resources :passwords, controller: 'rails_jwt_auth/passwords', only: [:create, :update]"
|
14
|
+
route "resources :invitations, controller: 'rails_jwt_auth/invitations', only: [:create, :update]"
|
16
15
|
end
|
17
16
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class RailsJwtAuth::MigrateGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __dir__)
|
5
|
+
|
6
|
+
def self.next_migration_number(_dir)
|
7
|
+
Time.current.strftime('%Y%m%d%H%M%S')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_initializer_file
|
11
|
+
migration_template 'migration.rb', "db/migrate/create_#{RailsJwtAuth.table_name}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def migration_version
|
15
|
+
"[#{Rails.version.split('.')[0..1].join('.')}]"
|
16
|
+
end
|
17
|
+
end
|
@@ -5,11 +5,8 @@ RailsJwtAuth.setup do |config|
|
|
5
5
|
# field name used to authentication with password
|
6
6
|
#config.auth_field_name = 'email'
|
7
7
|
|
8
|
-
#
|
9
|
-
#config.
|
10
|
-
|
11
|
-
# regex used to Validate email format
|
12
|
-
#config.email_regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
|
8
|
+
# define email field name used to send emails
|
9
|
+
#config.email_field_name = 'email'
|
13
10
|
|
14
11
|
# expiration time for generated tokens
|
15
12
|
#config.jwt_expiration_time = 7.days
|
@@ -18,34 +15,33 @@ RailsJwtAuth.setup do |config|
|
|
18
15
|
#config.jwt_issuer = 'RailsJwtAuth'
|
19
16
|
|
20
17
|
# number of simultaneously sessions for an user
|
21
|
-
#config.
|
18
|
+
#config.simultaneous_sessions = 2
|
22
19
|
|
23
20
|
# mailer sender
|
24
21
|
#config.mailer_sender = 'initialize-mailer_sender@example.com'
|
25
22
|
|
26
|
-
# url used to create email link with confirmation token
|
27
|
-
#config.confirmation_url = 'http://frontend.com/confirmation'
|
28
|
-
|
29
23
|
# expiration time for confirmation tokens
|
30
24
|
#config.confirmation_expiration_time = 1.day
|
31
25
|
|
26
|
+
# expiration time for reset password tokens
|
27
|
+
#config.reset_password_expiration_time = 1.day
|
28
|
+
|
29
|
+
# time an invitation is valid after sent
|
30
|
+
# config.invitation_expiration_time = 2.days
|
31
|
+
|
32
|
+
# url used to create email link with confirmation token
|
33
|
+
#config.confirmations_url = 'http://frontend.com/confirmation'
|
34
|
+
|
32
35
|
# url used to create email link with reset password token
|
33
|
-
#config.
|
36
|
+
#config.reset_passwords_url = 'http://frontend.com/reset_password'
|
34
37
|
|
35
38
|
# url used to create email link with set password token
|
36
|
-
#
|
39
|
+
# by set_and_send_password_instructions method
|
40
|
+
#config.set_passwords_url = 'http://frontend.com/set_password'
|
37
41
|
|
38
|
-
#
|
39
|
-
#config.
|
42
|
+
# url used to create email link with activation token parameter to accept invitation
|
43
|
+
#config.invitations_url = 'http://frontend.com/accept_invitation'
|
40
44
|
|
41
45
|
# uses deliver_later to send emails instead of deliver method
|
42
46
|
#config.deliver_later = false
|
43
|
-
|
44
|
-
# Invitable configuration
|
45
|
-
#
|
46
|
-
# Time an invitation is valid after sent
|
47
|
-
# config.invitation_expiration_time = 2.days
|
48
|
-
#
|
49
|
-
# URL used to create email link to activate invitation
|
50
|
-
# config.accept_invitation_url = 'http://frontend.com/accept_invitation'
|
51
47
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Create<%= RailsJwtAuth.model_name.pluralize %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :<%= RailsJwtAuth.table_name %> do |t|
|
4
|
+
t.string :email
|
5
|
+
t.string :password_digest
|
6
|
+
t.string :auth_tokens
|
7
|
+
|
8
|
+
## Confirmable
|
9
|
+
# t.string :unconfirmed_email
|
10
|
+
# t.string :confirmation_token
|
11
|
+
# t.datetime :confirmation_sent_at
|
12
|
+
# t.datetime :confirmed_at
|
13
|
+
|
14
|
+
## Recoverable
|
15
|
+
# t.string :reset_password_token
|
16
|
+
# t.datetime :reset_password_sent_at
|
17
|
+
|
18
|
+
## Trackable
|
19
|
+
# t.string :last_sign_in_ip
|
20
|
+
# t.datetime :last_sign_in_at
|
21
|
+
|
22
|
+
## Invitable
|
23
|
+
# t.string :invitation_token
|
24
|
+
# t.datetime :invitation_sent_at
|
25
|
+
# t.datetime :invitation_accepted_at
|
26
|
+
# t.datetime :invitation_created_at
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,25 +1,4 @@
|
|
1
1
|
module RailsJwtAuth
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
require 'rails_jwt_auth/strategies/jwt'
|
4
|
-
|
5
|
-
config.generators do |g|
|
6
|
-
g.test_framework :rspec
|
7
|
-
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
8
|
-
end
|
9
|
-
|
10
|
-
initializer 'rails_jwt_auth.warden' do |app|
|
11
|
-
app.middleware.insert_after ActionDispatch::Callbacks, Warden::Manager do |manager|
|
12
|
-
manager.default_strategies :authentication_token
|
13
|
-
manager.failure_app = UnauthorizedController
|
14
|
-
end
|
15
|
-
|
16
|
-
Warden::Strategies.add(:authentication_token, Strategies::Jwt)
|
17
|
-
|
18
|
-
Warden::Manager.after_set_user except: :fetch do |record, warden, options|
|
19
|
-
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope])
|
20
|
-
record.update_tracked_fields!(warden.request)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
3
|
end
|
25
4
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'jwt'
|
2
|
+
|
3
|
+
module RailsJwtAuth
|
4
|
+
module JwtManager
|
5
|
+
def self.secret_key_base
|
6
|
+
Rails.application.secrets.secret_key_base || Rails.application.credentials.secret_key_base
|
7
|
+
end
|
8
|
+
|
9
|
+
# Encodes and signs JWT Payload with expiration
|
10
|
+
def self.encode(payload)
|
11
|
+
payload.reverse_merge!(meta)
|
12
|
+
JWT.encode(payload, secret_key_base)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Decodes the JWT with the signed secret
|
16
|
+
# [{"auth_token"=>"xxx", "exp"=>148..., "iss"=>"RJA"}, {"typ"=>"JWT", "alg"=>"HS256"}]
|
17
|
+
def self.decode(token)
|
18
|
+
JWT.decode(token, secret_key_base)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Default options to be encoded in the token
|
22
|
+
def self.meta
|
23
|
+
{
|
24
|
+
exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i,
|
25
|
+
iss: RailsJwtAuth.jwt_issuer
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.decode_from_request(request)
|
30
|
+
decode(request.env['HTTP_AUTHORIZATION']&.split&.last)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RailsJwtAuth
|
2
|
+
module SpecHelpers
|
3
|
+
def sign_in(user)
|
4
|
+
allow_any_instance_of(RailsJwtAuth::AuthenticableHelper)
|
5
|
+
.to receive(:authenticate!).and_return(true)
|
6
|
+
|
7
|
+
allow_any_instance_of(RailsJwtAuth::AuthenticableHelper)
|
8
|
+
.to receive(:current_user).and_return(user.class.find(user.id))
|
9
|
+
end
|
10
|
+
|
11
|
+
def sign_out
|
12
|
+
allow_any_instance_of(RailsJwtAuth::AuthenticableHelper)
|
13
|
+
.to receive(:authenticate!).and_call_original
|
14
|
+
|
15
|
+
allow_any_instance_of(RailsJwtAuth::AuthenticableHelper)
|
16
|
+
.to receive(:current_user).and_call_original
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rails_jwt_auth.rb
CHANGED
@@ -1,62 +1,99 @@
|
|
1
|
-
require
|
2
|
-
require "bcrypt"
|
1
|
+
require 'bcrypt'
|
3
2
|
|
4
|
-
require
|
3
|
+
require 'rails_jwt_auth/engine'
|
4
|
+
require 'rails_jwt_auth/jwt_manager'
|
5
5
|
|
6
6
|
module RailsJwtAuth
|
7
|
+
InvalidEmailField = Class.new(StandardError)
|
8
|
+
InvalidAuthField = Class.new(StandardError)
|
9
|
+
NotConfirmationsUrl = Class.new(StandardError)
|
10
|
+
NotInvitationsUrl = Class.new(StandardError)
|
11
|
+
NotResetPasswordsUrl = Class.new(StandardError)
|
12
|
+
NotSetPasswordsUrl = Class.new(StandardError)
|
13
|
+
|
7
14
|
mattr_accessor :model_name
|
8
|
-
|
15
|
+
self.model_name = 'User'
|
9
16
|
|
10
17
|
mattr_accessor :auth_field_name
|
11
|
-
|
12
|
-
|
13
|
-
mattr_accessor :auth_field_email
|
14
|
-
@@auth_field_email = true
|
18
|
+
self.auth_field_name = 'email'
|
15
19
|
|
16
|
-
mattr_accessor :
|
17
|
-
|
20
|
+
mattr_accessor :email_field_name
|
21
|
+
self.email_field_name = 'email'
|
18
22
|
|
19
23
|
mattr_accessor :jwt_expiration_time
|
20
|
-
|
24
|
+
self.jwt_expiration_time = 7.days
|
21
25
|
|
22
26
|
mattr_accessor :jwt_issuer
|
23
|
-
|
27
|
+
self.jwt_issuer = 'RailsJwtAuth'
|
24
28
|
|
25
29
|
mattr_accessor :simultaneous_sessions
|
26
|
-
|
30
|
+
self.simultaneous_sessions = 2
|
27
31
|
|
28
32
|
mattr_accessor :mailer_sender
|
29
|
-
|
33
|
+
self.mailer_sender = 'initialize-mailer_sender@example.com'
|
30
34
|
|
31
|
-
mattr_accessor :
|
32
|
-
|
35
|
+
mattr_accessor :send_email_changed_notification
|
36
|
+
self.send_email_changed_notification = true
|
33
37
|
|
34
38
|
mattr_accessor :confirmation_expiration_time
|
35
|
-
|
39
|
+
self.confirmation_expiration_time = 1.day
|
36
40
|
|
37
|
-
mattr_accessor :
|
38
|
-
|
41
|
+
mattr_accessor :reset_password_expiration_time
|
42
|
+
self.reset_password_expiration_time = 1.day
|
39
43
|
|
40
|
-
mattr_accessor :
|
41
|
-
|
44
|
+
mattr_accessor :invitation_expiration_time
|
45
|
+
self.invitation_expiration_time = 2.days
|
42
46
|
|
43
|
-
mattr_accessor :
|
44
|
-
|
47
|
+
mattr_accessor :confirmations_url
|
48
|
+
self.confirmations_url = nil
|
45
49
|
|
46
|
-
mattr_accessor :
|
47
|
-
|
50
|
+
mattr_accessor :reset_passwords_url
|
51
|
+
self.reset_passwords_url = nil
|
48
52
|
|
49
|
-
mattr_accessor :
|
50
|
-
|
53
|
+
mattr_accessor :set_passwords_url
|
54
|
+
self.set_passwords_url = nil
|
51
55
|
|
52
|
-
mattr_accessor :
|
53
|
-
|
56
|
+
mattr_accessor :invitations_url
|
57
|
+
self.invitations_url = nil
|
58
|
+
|
59
|
+
mattr_accessor :deliver_later
|
60
|
+
self.deliver_later = false
|
54
61
|
|
55
62
|
def self.model
|
56
|
-
|
63
|
+
model_name.constantize
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.table_name
|
67
|
+
model_name.underscore.pluralize
|
57
68
|
end
|
58
69
|
|
59
70
|
def self.setup
|
60
71
|
yield self
|
61
72
|
end
|
73
|
+
|
74
|
+
def self.auth_field_name!
|
75
|
+
field_name = RailsJwtAuth.auth_field_name
|
76
|
+
klass = RailsJwtAuth.model
|
77
|
+
|
78
|
+
unless field_name.present? &&
|
79
|
+
(klass.respond_to?(:column_names) && klass.column_names.include?(field_name) ||
|
80
|
+
klass.respond_to?(:fields) && klass.fields[field_name])
|
81
|
+
raise RailsJwtAuth::InvalidAuthField
|
82
|
+
end
|
83
|
+
|
84
|
+
field_name
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.email_field_name!
|
88
|
+
field_name = RailsJwtAuth.email_field_name
|
89
|
+
klass = RailsJwtAuth.model
|
90
|
+
|
91
|
+
unless field_name.present? &&
|
92
|
+
(klass.respond_to?(:column_names) && klass.column_names.include?(field_name) ||
|
93
|
+
klass.respond_to?(:fields) && klass.fields[field_name])
|
94
|
+
raise RailsJwtAuth::InvalidEmailField
|
95
|
+
end
|
96
|
+
|
97
|
+
field_name
|
98
|
+
end
|
62
99
|
end
|
metadata
CHANGED
@@ -1,71 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '5.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '5.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: warden
|
14
|
+
name: bcrypt
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1
|
19
|
+
version: '3.1'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1
|
26
|
+
version: '3.1'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: jwt
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
33
|
+
version: '2.1'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1
|
40
|
+
version: '2.1'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: rails
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
47
|
+
version: '5.0'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '6.1'
|
62
51
|
type: :runtime
|
63
52
|
prerelease: false
|
64
53
|
version_requirements: !ruby/object:Gem::Requirement
|
65
54
|
requirements:
|
66
|
-
- - "
|
55
|
+
- - ">="
|
67
56
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
57
|
+
version: '5.0'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '6.1'
|
69
61
|
description: Rails authentication solution based on Warden and JWT and inspired by
|
70
62
|
Devise.
|
71
63
|
email:
|
@@ -77,9 +69,9 @@ files:
|
|
77
69
|
- MIT-LICENSE
|
78
70
|
- README.md
|
79
71
|
- Rakefile
|
72
|
+
- app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb
|
80
73
|
- app/controllers/concerns/rails_jwt_auth/params_helper.rb
|
81
74
|
- app/controllers/concerns/rails_jwt_auth/render_helper.rb
|
82
|
-
- app/controllers/concerns/rails_jwt_auth/warden_helper.rb
|
83
75
|
- app/controllers/rails_jwt_auth/confirmations_controller.rb
|
84
76
|
- app/controllers/rails_jwt_auth/invitations_controller.rb
|
85
77
|
- app/controllers/rails_jwt_auth/passwords_controller.rb
|
@@ -92,23 +84,21 @@ files:
|
|
92
84
|
- app/models/concerns/rails_jwt_auth/invitable.rb
|
93
85
|
- app/models/concerns/rails_jwt_auth/recoverable.rb
|
94
86
|
- app/models/concerns/rails_jwt_auth/trackable.rb
|
95
|
-
- app/validators/email_validator.rb
|
96
87
|
- app/views/rails_jwt_auth/mailer/confirmation_instructions.html.erb
|
88
|
+
- app/views/rails_jwt_auth/mailer/email_changed.html.erb
|
97
89
|
- app/views/rails_jwt_auth/mailer/reset_password_instructions.html.erb
|
98
90
|
- app/views/rails_jwt_auth/mailer/send_invitation.html.erb
|
99
91
|
- app/views/rails_jwt_auth/mailer/set_password_instructions.html.erb
|
100
92
|
- config/locales/en.yml
|
101
93
|
- lib/generators/rails_jwt_auth/install_generator.rb
|
94
|
+
- lib/generators/rails_jwt_auth/migrate_generator.rb
|
102
95
|
- lib/generators/templates/initializer.rb
|
96
|
+
- lib/generators/templates/migration.rb
|
103
97
|
- lib/rails_jwt_auth.rb
|
104
98
|
- lib/rails_jwt_auth/engine.rb
|
105
|
-
- lib/rails_jwt_auth/
|
106
|
-
- lib/rails_jwt_auth/
|
107
|
-
- lib/rails_jwt_auth/spec/helpers.rb
|
108
|
-
- lib/rails_jwt_auth/spec/not_authorized.rb
|
109
|
-
- lib/rails_jwt_auth/strategies/jwt.rb
|
99
|
+
- lib/rails_jwt_auth/jwt_manager.rb
|
100
|
+
- lib/rails_jwt_auth/spec_helpers.rb
|
110
101
|
- lib/rails_jwt_auth/version.rb
|
111
|
-
- lib/tasks/rails_token_jwt_tasks.rake
|
112
102
|
homepage: https://github.com/rjurado01/rails_jwt_auth
|
113
103
|
licenses:
|
114
104
|
- MIT
|
@@ -129,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
119
|
version: '0'
|
130
120
|
requirements: []
|
131
121
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.7.3
|
133
123
|
signing_key:
|
134
124
|
specification_version: 4
|
135
125
|
summary: Rails jwt authentication.
|