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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cb12ec56ae2eb4d3de12a3651610fd2f10068876e22a79f5d19b2a1e8c87f51
|
4
|
+
data.tar.gz: a7de6b200b4b09751e0d827d6414c1da15b11c601aa3c4d6a78a83db0a2eba26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
6
|
-
before_action :authenticate_user
|
5
|
+
include JwtApiAuth::Authentication
|
7
6
|
|
8
|
-
|
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
|
data/lib/jwt_api_auth.rb
CHANGED
@@ -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
|
data/lib/jwt_api_auth/version.rb
CHANGED
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
|
+
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-
|
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
|