rails_jwt_auth 0.23.2 → 1.0.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 +77 -219
- data/app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb +31 -0
- data/app/controllers/rails_jwt_auth/confirmations_controller.rb +3 -6
- data/app/controllers/rails_jwt_auth/invitations_controller.rb +5 -8
- data/app/controllers/rails_jwt_auth/passwords_controller.rb +3 -7
- data/app/controllers/rails_jwt_auth/sessions_controller.rb +13 -9
- data/app/mailers/rails_jwt_auth/mailer.rb +32 -47
- data/app/models/concerns/rails_jwt_auth/authenticatable.rb +31 -25
- data/app/models/concerns/rails_jwt_auth/confirmable.rb +54 -47
- data/app/models/concerns/rails_jwt_auth/invitable.rb +10 -11
- data/app/models/concerns/rails_jwt_auth/recoverable.rb +29 -28
- 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/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/lib/generators/rails_jwt_auth/install_generator.rb +4 -5
- data/lib/generators/rails_jwt_auth/migrate_generator.rb +17 -0
- data/lib/generators/templates/initializer.rb +15 -18
- data/lib/generators/templates/migration.rb +29 -0
- data/lib/rails_jwt_auth.rb +54 -20
- 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 +15 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +8 -10
- data/app/controllers/concerns/rails_jwt_auth/warden_helper.rb +0 -29
- data/lib/rails_jwt_auth/jwt/manager.rb +0 -41
- 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
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.
|
4
|
+
version: 1.0.0
|
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: 2018-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -77,9 +77,9 @@ files:
|
|
77
77
|
- MIT-LICENSE
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
|
+
- app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb
|
80
81
|
- app/controllers/concerns/rails_jwt_auth/params_helper.rb
|
81
82
|
- app/controllers/concerns/rails_jwt_auth/render_helper.rb
|
82
|
-
- app/controllers/concerns/rails_jwt_auth/warden_helper.rb
|
83
83
|
- app/controllers/rails_jwt_auth/confirmations_controller.rb
|
84
84
|
- app/controllers/rails_jwt_auth/invitations_controller.rb
|
85
85
|
- app/controllers/rails_jwt_auth/passwords_controller.rb
|
@@ -99,16 +99,14 @@ files:
|
|
99
99
|
- app/views/rails_jwt_auth/mailer/set_password_instructions.html.erb
|
100
100
|
- config/locales/en.yml
|
101
101
|
- lib/generators/rails_jwt_auth/install_generator.rb
|
102
|
+
- lib/generators/rails_jwt_auth/migrate_generator.rb
|
102
103
|
- lib/generators/templates/initializer.rb
|
104
|
+
- lib/generators/templates/migration.rb
|
103
105
|
- lib/rails_jwt_auth.rb
|
104
106
|
- 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
|
107
|
+
- lib/rails_jwt_auth/jwt_manager.rb
|
108
|
+
- lib/rails_jwt_auth/spec_helpers.rb
|
110
109
|
- lib/rails_jwt_auth/version.rb
|
111
|
-
- lib/tasks/rails_token_jwt_tasks.rake
|
112
110
|
homepage: https://github.com/rjurado01/rails_jwt_auth
|
113
111
|
licenses:
|
114
112
|
- MIT
|
@@ -129,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
127
|
version: '0'
|
130
128
|
requirements: []
|
131
129
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.7.
|
130
|
+
rubygems_version: 2.7.6
|
133
131
|
signing_key:
|
134
132
|
specification_version: 4
|
135
133
|
summary: Rails jwt authentication.
|
@@ -1,29 +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
|
-
return unless defined?(RailsJwtAuth::Spec::NotAuthorized)
|
23
|
-
|
24
|
-
base.send(:rescue_from, RailsJwtAuth::Spec::NotAuthorized) do
|
25
|
-
render json: {}, status: 401
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'jwt'
|
2
|
-
|
3
|
-
module RailsJwtAuth
|
4
|
-
module Jwt
|
5
|
-
class Manager
|
6
|
-
def self.secret_key_base
|
7
|
-
Rails.application.secrets.secret_key_base || Rails.application.credentials.secret_key_base
|
8
|
-
end
|
9
|
-
|
10
|
-
# Encodes and signs JWT Payload with expiration
|
11
|
-
def self.encode(payload)
|
12
|
-
payload.reverse_merge!(meta)
|
13
|
-
JWT.encode(payload, secret_key_base)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Decodes the JWT with the signed secret
|
17
|
-
# [{"auth_token"=>"xxx", "exp"=>148..., "iss"=>"RJA"}, {"typ"=>"JWT", "alg"=>"HS256"}]
|
18
|
-
def self.decode(token)
|
19
|
-
JWT.decode(token, secret_key_base)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Validates the payload hash for expiration and meta claims
|
23
|
-
def self.valid_payload?(payload)
|
24
|
-
payload && !expired?(payload) && payload['iss'] == meta[:iss]
|
25
|
-
end
|
26
|
-
|
27
|
-
# Default options to be encoded in the token
|
28
|
-
def self.meta
|
29
|
-
{
|
30
|
-
exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i,
|
31
|
-
iss: RailsJwtAuth.jwt_issuer
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
# Validates if the token is expired by exp parameter
|
36
|
-
def self.expired?(payload)
|
37
|
-
Time.at(payload['exp']) < Time.now
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
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
|