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,27 +0,0 @@
|
|
1
|
-
module RailsJwtAuth
|
2
|
-
module WardenHelper
|
3
|
-
def signed_in?
|
4
|
-
!current_user.nil?
|
5
|
-
end
|
6
|
-
|
7
|
-
def current_user
|
8
|
-
warden.user
|
9
|
-
end
|
10
|
-
|
11
|
-
def warden
|
12
|
-
request.env['warden']
|
13
|
-
end
|
14
|
-
|
15
|
-
def authenticate!
|
16
|
-
warden.authenticate!(store: false)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.included(base)
|
20
|
-
return unless Rails.env.test? && base.name == 'ApplicationController'
|
21
|
-
|
22
|
-
base.send(:rescue_from, RailsJwtAuth::Spec::NotAuthorized) do
|
23
|
-
render json: {}, status: 401
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'jwt'
|
2
|
-
|
3
|
-
module RailsJwtAuth
|
4
|
-
module Jwt
|
5
|
-
class Manager
|
6
|
-
# Encodes and signs JWT Payload with expiration
|
7
|
-
def self.encode(payload)
|
8
|
-
payload.reverse_merge!(meta)
|
9
|
-
JWT.encode(payload, Rails.application.secrets.secret_key_base)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Decodes the JWT with the signed secret
|
13
|
-
# [{"auth_token"=>"xxx", "exp"=>148..., "iss"=>"RJA"}, {"typ"=>"JWT", "alg"=>"HS256"}]
|
14
|
-
def self.decode(token)
|
15
|
-
JWT.decode(token, Rails.application.secrets.secret_key_base)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Validates the payload hash for expiration and meta claims
|
19
|
-
def self.valid_payload?(payload)
|
20
|
-
payload && !expired?(payload) && payload['iss'] == meta[:iss]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Default options to be encoded in the token
|
24
|
-
def self.meta
|
25
|
-
{
|
26
|
-
exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i,
|
27
|
-
iss: RailsJwtAuth.jwt_issuer
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
# Validates if the token is expired by exp parameter
|
32
|
-
def self.expired?(payload)
|
33
|
-
Time.at(payload['exp']) < Time.now
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rails_jwt_auth/jwt/manager'
|
2
|
-
|
3
|
-
module RailsJwtAuth
|
4
|
-
module Jwt
|
5
|
-
class Request
|
6
|
-
def initialize(request)
|
7
|
-
return unless request.env['HTTP_AUTHORIZATION']
|
8
|
-
@jwt = request.env['HTTP_AUTHORIZATION'].split.last
|
9
|
-
|
10
|
-
begin
|
11
|
-
@jwt_info = RailsJwtAuth::Jwt::Manager.decode(@jwt)
|
12
|
-
rescue JWT::ExpiredSignature, JWT::VerificationError
|
13
|
-
@jwt_info = false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def valid?
|
18
|
-
@jwt && @jwt_info && RailsJwtAuth::Jwt::Manager.valid_payload?(payload)
|
19
|
-
end
|
20
|
-
|
21
|
-
def payload
|
22
|
-
@jwt_info ? @jwt_info[0] : nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def header
|
26
|
-
@jwt_info ? @jwt_info[1] : nil
|
27
|
-
end
|
28
|
-
|
29
|
-
def auth_token
|
30
|
-
payload ? payload['auth_token'] : nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module RailsJwtAuth
|
2
|
-
module Spec
|
3
|
-
module Helpers
|
4
|
-
require 'rails_jwt_auth/spec/not_authorized'
|
5
|
-
|
6
|
-
def sign_out
|
7
|
-
allow(controller).to receive(:authenticate!).and_raise(RailsJwtAuth::Spec::NotAuthorized)
|
8
|
-
end
|
9
|
-
|
10
|
-
def sign_in(user)
|
11
|
-
manager = Warden::Manager.new(nil, &Rails.application.config.middleware.detect{|m| m.name == 'Warden::Manager'}.block)
|
12
|
-
request.env['warden'] = Warden::Proxy.new(request.env, manager)
|
13
|
-
request.env['warden'].set_user(user, store: false)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rails_jwt_auth/jwt/request'
|
2
|
-
|
3
|
-
module RailsJwtAuth
|
4
|
-
module Strategies
|
5
|
-
class Jwt < ::Warden::Strategies::Base
|
6
|
-
def authenticate!
|
7
|
-
jwt = RailsJwtAuth::Jwt::Request.new(request)
|
8
|
-
|
9
|
-
if jwt.valid? && (model = RailsJwtAuth.model.get_by_token(jwt.auth_token))
|
10
|
-
return success!(model)
|
11
|
-
end
|
12
|
-
|
13
|
-
fail!('strategies.authentication_token.failed')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|