jwt_api_auth 0.0.1.pre.4 → 0.0.1.pre.5

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: 323d161ac86bd83b3c255488bd6122470f2ecc63966170513c0d1c640464a189
4
- data.tar.gz: e1afdc4450baf12fcc47feef3494b2d03606f61e45152dc0c3cbb505e9863108
3
+ metadata.gz: 5cb12ec56ae2eb4d3de12a3651610fd2f10068876e22a79f5d19b2a1e8c87f51
4
+ data.tar.gz: a7de6b200b4b09751e0d827d6414c1da15b11c601aa3c4d6a78a83db0a2eba26
5
5
  SHA512:
6
- metadata.gz: 9d48fd22997c8bc8eb32caf91b5c4044fee24b1661581fe4f2bccaec80d8cf5ab846fc17d299c075c326c0dcc5c29bd674a16a189af2e88d93ea45102058c1c9
7
- data.tar.gz: eb81d52a94de39cf3679a98e7595fb0f746e588e04aa3a84b03253126145253c6e88b4ddb0b58af7aaf8455155c45e424dd6dfe48098a7ec8dea65086a3d3e33
6
+ metadata.gz: 2b962f0af973fe0571454cd51182b9d15abf2dd6d78f8fb5a5dd27aac3864be14d1d80e2b6289b4b987cedae0955788b2b11ef5ad3e7336ad01e8b9b0a87ab1e
7
+ data.tar.gz: 57801bd10539344e71911a8bd68eb95927f9c89477d63bf11d904bab00228790512de04c2b71f120bcbe23864f72b2dbff1d9c9b88ce949e340a4a027149af26
@@ -2,24 +2,12 @@
2
2
 
3
3
  module JwtApiAuth
4
4
  class ApplicationController < ActionController::Base
5
- skip_before_action :verify_authenticity_token
6
- before_action :authenticate_user
5
+ include JwtApiAuth::Authentication
7
6
 
8
- rescue_from ::JWT::DecodeError do
9
- head :unauthorized
10
- end
7
+ skip_before_action :verify_authenticity_token
11
8
 
12
9
  rescue_from ActiveRecord::RecordNotFound do
13
10
  head :not_found
14
11
  end
15
-
16
- private
17
-
18
- def authenticate_user
19
- token = request.headers['Authorization']&.split('Bearer ')&.last
20
- ::JWT.decode token, JwtApiAuth.token_secret.call, true, { algorithm: 'HS256' }
21
-
22
- head :unauthorized unless token
23
- end
24
12
  end
25
13
  end
@@ -3,6 +3,7 @@
3
3
  require 'jwt'
4
4
  require 'jwt_api_auth/engine'
5
5
  require 'jwt_api_auth/helpers'
6
+ require 'jwt_api_auth/authentication'
6
7
 
7
8
  module JwtApiAuth
8
9
  ActiveSupport.on_load(:action_controller) do
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JwtApiAuth
4
+ module Authentication
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_action :authenticate_user
9
+
10
+ rescue_from ::JWT::DecodeError do
11
+ head :unauthorized
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def authenticate_user
18
+ token = request.headers['Authorization']&.split('Bearer ')&.last
19
+ ::JWT.decode token, JwtApiAuth.token_secret.call, true, { algorithm: 'HS256' }
20
+
21
+ head :unauthorized unless token
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JwtApiAuth
4
- VERSION = '0.0.1.pre.4'
4
+ VERSION = '0.0.1.pre.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt_api_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.4
4
+ version: 0.0.1.pre.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Stügelmayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-21 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -269,6 +269,7 @@ files:
269
269
  - app/views/layouts/jwt_api_auth/application.html.erb
270
270
  - config/routes.rb
271
271
  - lib/jwt_api_auth.rb
272
+ - lib/jwt_api_auth/authentication.rb
272
273
  - lib/jwt_api_auth/engine.rb
273
274
  - lib/jwt_api_auth/helpers.rb
274
275
  - lib/jwt_api_auth/version.rb