usps-jwt_auth 1.6.0 → 1.7.0
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/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/lib/usps/jwt_auth/cable_connection.rb +6 -6
- data/lib/usps/jwt_auth/concern.rb +4 -30
- data/lib/usps/jwt_auth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6552aba8b28b9fdf0b8ee9e4097eab57d697a4ddccebb64e2e1e9f510f807592
|
|
4
|
+
data.tar.gz: bd3be43c2fefd25b2cfcf1a5aad396c1353a094aedcad8e04f19d3a9a29c22c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: added992bce72897a2a506d5067c47723f08109f33e09bc14e7dfcc9bddcff60f2feb0560d43316bd1076ee0ffe3f8e7a5688461bb6b42ee86bdb534915966f0
|
|
7
|
+
data.tar.gz: 5c7c657dde9dae889262c5b0d935d27d6131019437e957214f83613629427036e98508b007ea67940368024f076c4291f864288aafc78f49a3a0507a608e38cb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -108,8 +108,8 @@ module ApplicationCable
|
|
|
108
108
|
end
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
This authenticates a connection from the
|
|
112
|
-
identifies it by `current_user`. Impersonation doesn't apply
|
|
111
|
+
This authenticates a connection from the session, with the same checks as a request, and
|
|
112
|
+
identifies it by `current_user`. Impersonation doesn't apply to sockets.
|
|
113
113
|
|
|
114
114
|
A socket closes within a heartbeat (3 seconds) of its token expiring. The client then reconnects,
|
|
115
|
-
which succeeds if the
|
|
115
|
+
which succeeds if the token has been refreshed and is rejected for good otherwise.
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
module Usps
|
|
4
4
|
module JwtAuth
|
|
5
|
-
# Authenticates an Action Cable connection from the
|
|
6
|
-
#
|
|
5
|
+
# Authenticates an Action Cable connection from the session, and holds the socket to that token's
|
|
6
|
+
# expiry. Channels only authorize at subscribe, so a socket would otherwise outlive its token.
|
|
7
7
|
#
|
|
8
8
|
module CableConnection
|
|
9
9
|
def self.included(base) = base.identified_by(:current_user)
|
|
10
10
|
|
|
11
11
|
def connect
|
|
12
|
-
data, expires_at =
|
|
12
|
+
data, expires_at = verified_token
|
|
13
13
|
self.current_user = member_for(data['certificate']) || reject_unauthorized_connection
|
|
14
14
|
@token_expires_at = expires_at.to_i
|
|
15
15
|
rescue JWT::DecodeError, ActiveRecord::RecordNotFound
|
|
@@ -17,7 +17,7 @@ module Usps
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Runs on every heartbeat, for every connection, so this must stay a plain comparison. Closing with
|
|
20
|
-
# reconnect allowed sends the client back through `connect`, which picks up a refreshed
|
|
20
|
+
# reconnect allowed sends the client back through `connect`, which picks up a refreshed token or
|
|
21
21
|
# rejects the socket for good. Action Cable calls this public method itself, so recheck the override
|
|
22
22
|
# when upgrading Rails.
|
|
23
23
|
def beat
|
|
@@ -26,9 +26,9 @@ module Usps
|
|
|
26
26
|
|
|
27
27
|
private
|
|
28
28
|
|
|
29
|
-
def
|
|
29
|
+
def verified_token
|
|
30
30
|
Decode.new.verified(
|
|
31
|
-
|
|
31
|
+
request.session[:jwt], audience: [JwtAuth.config.audience], issuer: Regexp.union(JwtAuth.config.issuers)
|
|
32
32
|
)
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -48,9 +48,7 @@ module Usps
|
|
|
48
48
|
def load_current_user
|
|
49
49
|
assign_current_user
|
|
50
50
|
rescue JWT::DecodeError
|
|
51
|
-
|
|
52
|
-
retry if fetch_jwt.present?
|
|
53
|
-
|
|
51
|
+
clear_jwt
|
|
54
52
|
nil
|
|
55
53
|
rescue ActiveRecord::RecordNotFound => e
|
|
56
54
|
Bugsnag.notify(e)
|
|
@@ -92,33 +90,9 @@ module Usps
|
|
|
92
90
|
path.is_a?(String) && path.match?(%r{\A/(?![/\\])[^\x00-\x1f\x7f]*\z}) ? path : root_path
|
|
93
91
|
end
|
|
94
92
|
|
|
95
|
-
def store_jwt(token)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def cookie_domain
|
|
101
|
-
JwtAuth.config.environment.production? ? '.aws.usps.org' : 'localhost'
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def clear_jwt
|
|
105
|
-
session[:jwt] = nil
|
|
106
|
-
cookies.delete(:jwt, domain: cookie_domain)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# Only the copy that failed goes. The session's copy can be older than a cookie another application
|
|
110
|
-
# has since refreshed, and that cookie is shared by every application under the domain.
|
|
111
|
-
def discard_rejected_jwt
|
|
112
|
-
if session[:jwt].present?
|
|
113
|
-
session[:jwt] = nil
|
|
114
|
-
else
|
|
115
|
-
cookies.delete(:jwt, domain: cookie_domain)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def fetch_jwt
|
|
120
|
-
session[:jwt] || cookies[:jwt]
|
|
121
|
-
end
|
|
93
|
+
def store_jwt(token) = session[:jwt] = token
|
|
94
|
+
def clear_jwt = session[:jwt] = nil
|
|
95
|
+
def fetch_jwt = session[:jwt]
|
|
122
96
|
|
|
123
97
|
def jwt = decode_jwt(fetch_jwt)
|
|
124
98
|
|