usps-jwt_auth 0.2.7 → 0.3.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: e46b14c6f88047e2a91d8b3dee98dc62b77453e8df259af908673471215eaf61
4
- data.tar.gz: 758b74fc5fe973143b1bf23cb73df23c27fbf97953e51a244cdb5fda41dc6140
3
+ metadata.gz: a7b812b3bd3cd3dbaf68b5e3d0659c91ac872a9852dbd2e9da849a6f74676cdf
4
+ data.tar.gz: 5d033a22ad91830bf7971ef4a3239febe1a5bafb733100b4ea086741c3778eed
5
5
  SHA512:
6
- metadata.gz: 64525963c48bbc9485cf639e0d09473288df601d3b6b85c3d7077cda7da694395d7d5070de76f3de5c5fc27498d42b8cead943ce670f5f39b3582c8fcc7d8e5f
7
- data.tar.gz: 6b345b3c1f03158242261cea4e01d95939a3c87e0f4af77efb0b4c129b55ddc284d4d0c7a10d5e45a75e6f6d0ccaca4e9b81d9e8b40135aec81b92a6728fa311
6
+ metadata.gz: 2f21bdd0c4436166fd1556b33087dfa669f818d355b807424c1bc6e62f1ce68807a9521e92f4fda2306c9552e837fc120f8543f4dcfef1891e71958d5fa21518
7
+ data.tar.gz: 3f33edaba5c9c85e508c6c6d0b94f753939e9a37a224024a42eea189114ed14b6509b518e2559439f6b7f271dc61fba01ad3108d51de5f1cfa622e6d7a5d7b5f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-jwt_auth (0.2.7)
4
+ usps-jwt_auth (0.3.0)
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?
@@ -70,8 +71,9 @@ module Usps
70
71
  return if params[:jwt].blank?
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)
75
77
  end
76
78
 
77
79
  def store_jwt(token)
@@ -110,6 +112,15 @@ module Usps
110
112
  redirect_to(url, allow_other_host: true)
111
113
  end
112
114
 
115
+ def ensure_valid_jwt_has_valid_member!
116
+ fetch_jwt
117
+ jwt_user
118
+ rescue ActiveRecord::RecordNotFound
119
+ clear_jwt
120
+ @current_user = nil
121
+ raise IncorrectLogin, 'Valid login without valid member record'
122
+ end
123
+
113
124
  def stub_jwt!
114
125
  raise 'Cannot stub JWT outside of test environment!' unless JwtAuth.config.environment.test?
115
126
 
@@ -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 = '0.2.7'
5
+ VERSION = '0.3.0'
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: 0.2.7
4
+ version: 0.3.0
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