authify-middleware 0.0.2 → 0.0.3
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 +4 -4
- data/lib/authify/middleware/jwt_auth.rb +34 -28
- data/lib/authify/middleware/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca1abb9985205ef5498ff6ee21bd3545d2823a01
|
4
|
+
data.tar.gz: d55bff436475c78126b6d3e7f52b436e38b11b6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7486aa62b037bc13ed3fcf7784c458a56559dc72d281bc3518260a3b2a2416c7332ede384cec9bd0c0c23fe702e8d8c92649c3e29a2f5a9a36195cfce83e93b7
|
7
|
+
data.tar.gz: 6e3d8ee82ab128677ff52212518a3b8da10f4dd051f42235f7cd3d4710e2b8163ec7ea277d1ac3150960f3b710571e8aa147dae6c6acdfa8cfb8f58d252a574c
|
@@ -9,39 +9,45 @@ module Authify
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# rubocop:disable Metrics/MethodLength
|
12
|
+
# rubocop:disable Metrics/AbcSize
|
12
13
|
def call(env)
|
13
|
-
|
14
|
-
bearer = env.fetch('HTTP_AUTHORIZATION', '').slice(7..-1)
|
15
|
-
payload, _header = JWT.decode bearer, public_key, true, options
|
14
|
+
payload = process_token
|
16
15
|
|
17
16
|
env[:scopes] = payload['scopes']
|
18
17
|
env[:user] = payload['user']
|
19
|
-
|
18
|
+
env[:authenticated] = Time.now
|
19
|
+
rescue JWT::DecodeError => e
|
20
|
+
env[:authenticated] = false
|
21
|
+
env[:authentication_errors] ||= []
|
22
|
+
env[:authentication_errors] << e
|
23
|
+
rescue JWT::ExpiredSignature => e
|
24
|
+
env[:authenticated] = false
|
25
|
+
env[:authentication_errors] ||= []
|
26
|
+
env[:authentication_errors] << e
|
27
|
+
rescue JWT::InvalidIssuerError => e
|
28
|
+
env[:authenticated] = false
|
29
|
+
env[:authentication_errors] ||= []
|
30
|
+
env[:authentication_errors] << e
|
31
|
+
rescue JWT::InvalidIatError => e
|
32
|
+
env[:authenticated] = false
|
33
|
+
env[:authentication_errors] ||= []
|
34
|
+
env[:authentication_errors] << e
|
35
|
+
ensure
|
20
36
|
@app.call env
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
[
|
35
|
-
403,
|
36
|
-
{ 'Content-Type' => 'text/plain' },
|
37
|
-
['The token does not have a valid issuer.']
|
38
|
-
]
|
39
|
-
rescue JWT::InvalidIatError
|
40
|
-
[
|
41
|
-
403,
|
42
|
-
{ 'Content-Type' => 'text/plain' },
|
43
|
-
['The token does not have a valid "issued at" time.']
|
44
|
-
]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def process_token
|
42
|
+
options = {
|
43
|
+
algorithm: 'ES256',
|
44
|
+
verify_iss: true,
|
45
|
+
verify_iat: true,
|
46
|
+
iss: CONFIG[:jwt][:issuer]
|
47
|
+
}
|
48
|
+
|
49
|
+
bearer = env.fetch('HTTP_AUTHORIZATION', '').slice(7..-1)
|
50
|
+
JWT.decode(bearer, public_key, true, options)[0]
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authify-middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gnagy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|