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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4d0a7fa31dda367cd91b0c0433d3bb13bd0193c9bfb7012b88a9551d97acac8
4
- data.tar.gz: 30e476a5bf00f777ea2c00c0ea3ab0c766df8b24d7b992aaaf6b088ddcaa167a
3
+ metadata.gz: 6552aba8b28b9fdf0b8ee9e4097eab57d697a4ddccebb64e2e1e9f510f807592
4
+ data.tar.gz: bd3be43c2fefd25b2cfcf1a5aad396c1353a094aedcad8e04f19d3a9a29c22c0
5
5
  SHA512:
6
- metadata.gz: 5711447a343cb032db3e8eb6f60777adb8fdaa35dd9a59a17878df0a46a5e2c514f65db686cc704f3c5a0372b4e84e7f71ba497624c8945b0de46390d6410f25
7
- data.tar.gz: '037857f4ecb476e36257279824af46ff17ea32310acf99e33ac7b479afd5ec4f84e85d7d7f49a2e4fefa194a56e82ec7b0a002011d98cfb213d2dc4622dd9c7c'
6
+ metadata.gz: added992bce72897a2a506d5067c47723f08109f33e09bc14e7dfcc9bddcff60f2feb0560d43316bd1076ee0ffe3f8e7a5688461bb6b42ee86bdb534915966f0
7
+ data.tar.gz: 5c7c657dde9dae889262c5b0d935d27d6131019437e957214f83613629427036e98508b007ea67940368024f076c4291f864288aafc78f49a3a0507a608e38cb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-jwt_auth (1.6.0)
4
+ usps-jwt_auth (1.7.0)
5
5
  activesupport (~> 8.0)
6
6
  colorize (~> 1.1)
7
7
  fileutils (~> 1.7)
data/README.md CHANGED
@@ -108,8 +108,8 @@ module ApplicationCable
108
108
  end
109
109
  ```
110
110
 
111
- This authenticates a connection from the `jwt` cookie, with the same checks as a request, and
112
- identifies it by `current_user`. Impersonation doesn't apply, since it lives in the session.
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 cookie has been refreshed and is rejected for good otherwise.
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 shared cookie, and holds the socket to that
6
- # token's expiry. Channels only authorize at subscribe, so a socket would otherwise outlive its token.
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 = verified_cookie
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 cookie or
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 verified_cookie
29
+ def verified_token
30
30
  Decode.new.verified(
31
- cookies[:jwt], audience: [JwtAuth.config.audience], issuer: Regexp.union(JwtAuth.config.issuers)
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
- discard_rejected_jwt
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
- session[:jwt] = token
97
- cookies[:jwt] = { value: token, domain: cookie_domain, httponly: true }
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Usps
4
4
  module JwtAuth
5
- VERSION = '1.6.0'
5
+ VERSION = '1.7.0'
6
6
 
7
7
  # The version of the jwt-sso login contract that this release implements.
8
8
  LOGIN_VERSION = 2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander