usps-jwt_auth 1.0.0.pre.rc.1 → 1.0.0.pre.rc.2

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: 848bc0fc3b35ca707a3a7666a718615411f66e6c6700ab6f0caca23cf2bc8862
4
- data.tar.gz: efbd63572b9f486a1240c38d10ccb1aa054ae2ddd82ca5837c78bb41b479b7ea
3
+ metadata.gz: 71ef9d51e59a0dea30294ac18846b64c4bc9bbf60023d497d6eac38fbcfda5d1
4
+ data.tar.gz: dae70a2acb6d3a363ed3f597986dc05336a3707f81ebd06fc2b859eb51c34aad
5
5
  SHA512:
6
- metadata.gz: 601620bea4da5310b31744283d4bb2a4a6d9b6f19f6d981a1d864f740b9e00d70f72e984dfaef234ce53e32ab30a8563540eee5fe73c546ac7d9864e3bba97be
7
- data.tar.gz: e9d31e6bc397f6b577cba0b30e334c718eca12d9e68f0f050241b3bdcfe35d27db0c2cf6f9c315a57e13534235a01131530a6142a423a884b738966ec2f35ea8
6
+ metadata.gz: baca203a5bffd8bfcec36f9308c8bafb34420756290a61adad7e74b6e5652bec2d5a3b1e439407598ed9f24f69a9d835b641a343e344f560290793df12a5da9f
7
+ data.tar.gz: da388afd9815b8d535ff9f57a6d7cf61f48849e4538360e84e390e523fff88fa2aed340a82f43a154ea486449a167feaed335ef919a0f0cc39a262eb15d8c111
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-jwt_auth (1.0.0.pre.rc.1)
4
+ usps-jwt_auth (1.0.0.pre.rc.2)
5
5
  activesupport (~> 8.0)
6
6
  colorize (~> 1.1)
7
7
  fileutils (~> 1.7)
@@ -5,6 +5,7 @@ module Usps
5
5
  # Controller helpers for handling JWT authentication
6
6
  #
7
7
  module Concern
8
+ # Gem rspec skips this block
8
9
  if defined?(ActiveSupport::Concern)
9
10
  extend ActiveSupport::Concern
10
11
 
@@ -41,7 +42,7 @@ module Usps
41
42
  ###############
42
43
 
43
44
  def current_user_from_jwt
44
- reset_session if params[:logout].present?
45
+ reset_session if params.key?(:logout)
45
46
  return if set_new_jwt
46
47
 
47
48
  load_current_user if fetch_jwt.present?
@@ -67,11 +68,13 @@ module Usps
67
68
  end
68
69
 
69
70
  def set_new_jwt
70
- return if params[:jwt].blank?
71
+ return if params[:jwt].blank? || @set_new_jwt
71
72
 
72
73
  store_jwt(params[:jwt])
73
- redirect_to(params[:path] || root_path) # Breaks the login loop
74
- nil
74
+ ensure_valid_jwt_has_valid_member!
75
+
76
+ redirect_to(params[:path] || root_path)
77
+ @set_new_jwt = true
75
78
  end
76
79
 
77
80
  def store_jwt(token)
@@ -101,6 +104,8 @@ module Usps
101
104
  end
102
105
 
103
106
  def redirect_to_login
107
+ return if @set_new_jwt
108
+
104
109
  url = 'https://www.usps.org/jwt'
105
110
  local = "#{url}?local&port=#{ENV.fetch('PORT', '3000')}"
106
111
  production = "#{url}?application=#{JwtAuth.config.audience}"
@@ -110,6 +115,16 @@ module Usps
110
115
  redirect_to(url, allow_other_host: true)
111
116
  end
112
117
 
118
+ def ensure_valid_jwt_has_valid_member!
119
+ fetch_jwt
120
+ jwt_user
121
+ rescue ActiveRecord::RecordNotFound
122
+ reset_session
123
+ clear_jwt
124
+ @current_user = nil
125
+ raise IncorrectLogin, 'Valid login without valid member record'
126
+ end
127
+
113
128
  def stub_jwt!
114
129
  raise 'Cannot stub JWT outside of test environment!' unless JwtAuth.config.environment.test?
115
130
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps
4
+ module JwtAuth
5
+ class IncorrectLogin < StandardError; end
6
+ end
7
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module JwtAuth
5
- VERSION = '1.0.0-rc.1'
5
+ VERSION = '1.0.0-rc.2'
6
6
  end
7
7
  end
data/lib/usps/jwt_auth.rb CHANGED
@@ -35,6 +35,7 @@ require_relative 'jwt_auth/version'
35
35
  require_relative 'jwt_auth/config'
36
36
  require_relative 'jwt_auth/encode'
37
37
  require_relative 'jwt_auth/decode'
38
+ require_relative 'jwt_auth/incorrect_login'
38
39
  require_relative 'jwt_auth/concern'
39
40
 
40
41
  # :nocov:
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.0.0.pre.rc.1
4
+ version: 1.0.0.pre.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -86,6 +86,7 @@ files:
86
86
  - lib/usps/jwt_auth/config.rb
87
87
  - lib/usps/jwt_auth/decode.rb
88
88
  - lib/usps/jwt_auth/encode.rb
89
+ - lib/usps/jwt_auth/incorrect_login.rb
89
90
  - lib/usps/jwt_auth/railtie.rb
90
91
  - lib/usps/jwt_auth/version.rb
91
92
  - sig/usps_jwt/auth.rbs