jwt_api_auth 0.0.1.pre.1 → 0.0.1.pre.6
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: 2d8037fc592eeb8985d15ec714a79a760a72070833fe199743305896af28c702
|
4
|
+
data.tar.gz: 03a845d6521ccecf8d91040ab1fcb7434efea54109d25b3c640c310bcd804574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b1438eb75ae7ed255d706eaf4dadc15d4e1cc33776d810f876cdca6ccd4cfc5c41448381aec35b908bfe04fddf9959f720b147c5b30b4d7354fee49f67c2a79
|
7
|
+
data.tar.gz: d2fef5f4aee3a28517ba36ef5443594c0562bf7a77440fd5199324e4b26f08e259971081556d04381261fa81f073a895b6fe41b840ece729032ba7cfc77e74c3
|
@@ -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
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_dependency 'jwt_api_auth/application_controller'
|
4
|
-
require_dependency 'jwt'
|
5
4
|
|
6
5
|
module JwtApiAuth
|
7
6
|
class AuthenticationController < ApplicationController
|
@@ -55,11 +54,14 @@ module JwtApiAuth
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def payload
|
58
|
-
{
|
57
|
+
{
|
58
|
+
sub: resource.id,
|
59
|
+
aud: JwtApiAuth.token_audience
|
60
|
+
}.delete_if { |_key, value| value.blank? }
|
59
61
|
end
|
60
62
|
|
61
63
|
def token
|
62
|
-
JWT.encode payload, JwtApiAuth.token_secret.call, 'HS256'
|
64
|
+
::JWT.encode payload, JwtApiAuth.token_secret.call, 'HS256'
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
data/lib/jwt_api_auth.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'jwt'
|
3
4
|
require 'jwt_api_auth/engine'
|
4
5
|
require 'jwt_api_auth/helpers'
|
6
|
+
require 'jwt_api_auth/authentication'
|
5
7
|
|
6
8
|
module JwtApiAuth
|
7
9
|
ActiveSupport.on_load(:action_controller) do
|
@@ -22,4 +24,11 @@ module JwtApiAuth
|
|
22
24
|
|
23
25
|
mattr_accessor :refresh_token_model
|
24
26
|
self.refresh_token_model = :refresh_token
|
27
|
+
|
28
|
+
mattr_accessor :token_audience
|
29
|
+
self.token_audience = nil
|
30
|
+
|
31
|
+
def self.setup
|
32
|
+
yield self
|
33
|
+
end
|
25
34
|
end
|
@@ -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.6
|
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
|
@@ -248,7 +248,7 @@ dependencies:
|
|
248
248
|
- - ">="
|
249
249
|
- !ruby/object:Gem::Version
|
250
250
|
version: '0'
|
251
|
-
description: JWT
|
251
|
+
description: JWT authentication for rails APIs
|
252
252
|
email:
|
253
253
|
- cristian@yellowspot.dev
|
254
254
|
executables: []
|
@@ -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
|
@@ -296,5 +297,5 @@ requirements: []
|
|
296
297
|
rubygems_version: 3.0.8
|
297
298
|
signing_key:
|
298
299
|
specification_version: 4
|
299
|
-
summary: JWT
|
300
|
+
summary: JWT authentication
|
300
301
|
test_files: []
|