strongmind-auth 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1526ec8b78d6caea36cd40f7c943b5e376a4da4fcb0a5f37a4a3222d658e612f
4
- data.tar.gz: f8bd96c7bb4d8658961224bf6c5ed9f1b9c2f9afd789d683e95afd3817a93864
3
+ metadata.gz: 87786b4c0cd6fa8ae92cbf99acb4ed2c189dd0ada276d738448d494fb146949b
4
+ data.tar.gz: b2020de0c578fe1f1ce781a4086c58b11518efe1338d3b7cba3f7c1a990574d1
5
5
  SHA512:
6
- metadata.gz: 06353b6d2d5f5d8554af61ba484e97ad6bc2b287a0d44a0e26f447a26df6e6c2de095b991f9b8002aaf676e3b6f080c1e095b1890ec2559f19bbbcb8292cb6d2
7
- data.tar.gz: b37c854e2fc115f6a802b5dee2fcc6d45393951a4ad6891f78efa80bb3e24aa7e4e5ab08c86ad7baa4b28c67e12db3eabad4a84d84f15ab312b4a07ecdd9b290
6
+ metadata.gz: 43cd1f34fb2a6804fef474cc46a65550772e4cb33c9b019b98a66754773ea31228297943d0018d2e7bafebbf1ad51a3cbf003685d80e03df8f18664314143806
7
+ data.tar.gz: 4b2dc4014ef8fd40bdd1e75041169622c2609977cff7680d65c08ec60107089bfee1c8490bbfddb7a069bf6cbd90dfc4d7b1354094a30cf07f9dd8e5f03fc612
@@ -89,7 +89,7 @@ module JwtUtilities
89
89
  def validate_tokens(tokens)
90
90
  return unless tokens[:error] == 'invalid_grant' || !tokens[:refresh_token]
91
91
 
92
- raise Strongmind::Exceptions::RefreshTokenExpired, tokens[:error]
92
+ raise Strongmind::Exceptions::RefreshTokenExpiredError, tokens[:error]
93
93
  end
94
94
 
95
95
  def generate_tokens(session_data)
@@ -11,12 +11,13 @@ module StrongMindNav
11
11
  @top_navbar_html = navbar[:top_navbar_html]
12
12
  @bottom_navbar_html = navbar[:bottom_navbar_html]
13
13
  @theme_css = navbar[:theme_css]
14
- rescue Strongmind::Exceptions::TokenNotFoundError, Strongmind::Exceptions::UserNotFoundError => e
14
+ rescue Strongmind::Exceptions::TokenNotFoundError, Strongmind::Exceptions::UserNotFoundError, Strongmind::Exceptions::RefreshTokenExpiredError => e
15
15
  Sentry.capture_exception(e)
16
16
  Rails.logger.error(e)
17
17
  flash[:alert] = e.inspect if Rails.env.development? || Rails.env.test?
18
18
  @stop_redirect = true if Rails.env.development? || Rails.env.test?
19
- render 'logins/index'
19
+ current_user.invalidate_all_sessions!
20
+ render 'logins/index' and return
20
21
  rescue Exception => e
21
22
  Sentry.capture_exception(e)
22
23
  Rails.logger.error(e)
@@ -18,6 +18,7 @@ module Users
18
18
 
19
19
  def endsession
20
20
  headers = { 'Cache-Control' => 'no-store' }
21
+ Rails.logger.info("endsession called with params: #{params}")
21
22
  if jwt_valid?(params[:logout_token], 'http://schemas.openid.net/event/backchannel-logout')
22
23
  payload, _header = JWT.decode(params[:logout_token], nil, false)
23
24
  user_identity = payload['sub']
@@ -17,11 +17,15 @@
17
17
  <%= button_to 'Sign in with StrongMind', '/users/auth/strongmind', style: 'display:none' %>
18
18
  <script type="text/javascript">
19
19
  // Submit the form on load
20
- window.addEventListener("load", (event) => {
20
+ function handleLoadEvent() {
21
21
  <% unless @stop_redirect %>
22
22
  document.forms[0].submit();
23
23
  <% end %>
24
- });
24
+ }
25
+
26
+ window.addEventListener("load", handleLoadEvent);
27
+ window.addEventListener("turbo:load", handleLoadEvent);
28
+
25
29
 
26
30
  </script>
27
31
  <div id="loading">
@@ -20,13 +20,6 @@ module Strongmind
20
20
  before_action :authenticate_user!
21
21
  before_action :fetch_common_nav
22
22
 
23
- rescue_from Strongmind::Exceptions::RefreshTokenExpiredError do
24
- current_user&.invalidate_all_sessions!
25
- redirect_to \"#{ENV['IDENTITY_BASE_URL']}/connect/endsession\", headers: {
26
- 'Content-Type' => 'application/json'
27
- }, allow_other_host: true
28
- end
29
-
30
23
  # Implement the list of menu items for the application
31
24
  # def menu_items
32
25
  # [
@@ -1,5 +1,5 @@
1
1
  module Strongmind
2
2
  module Auth
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
@@ -9,6 +9,10 @@ module Strongmind
9
9
 
10
10
  include Rails.application.routes.url_helpers
11
11
 
12
+ class TokenNotFoundError < StandardError; end
13
+
14
+ class UserNotFoundError < StandardError; end
15
+
12
16
  def initialize(user, request)
13
17
  raise Strongmind::Exceptions::UserNotFoundError, 'User not found' unless user.present?
14
18
  raise ArgumentError, 'Request not found' unless request.present?
@@ -35,7 +39,7 @@ module Strongmind
35
39
  end
36
40
 
37
41
  def fetch_navbar_data(nav_items)
38
- refresh_session if auth_client.token_expired?(token)
42
+ refresh_session
39
43
 
40
44
  connection.post(navbar_endpoint, nav_items.to_json, 'Authorization' => "Bearer #{token}")
41
45
  end
@@ -60,13 +64,21 @@ module Strongmind
60
64
  end
61
65
 
62
66
  def refresh_session
63
- begin
64
- session = Rails.cache.fetch(user.uid)
65
- auth_client.refresh_session(session:)
66
- Rails.cache.write(user.uid, session)
67
- rescue Faraday::BadRequestError => e
68
- Sentry.capture_exception(e, extra: { session:, request_body: request.body })
69
- end
67
+ session = Rails.cache.fetch(user.uid)
68
+ auth_client.refresh_session(session:)
69
+ Rails.cache.write(user.uid, session)
70
+ rescue PlatformSdk::Identity::ClientError => e
71
+ handle_refresh_error(e)
72
+ end
73
+
74
+ def handle_refresh_error(error)
75
+ raise Strongmind::Exceptions::RefreshTokenExpiredError, error.response[:body]['error'] if invalid_grant_error?(error)
76
+
77
+ raise error
78
+ end
79
+
80
+ def invalid_grant_error?(error)
81
+ error.response[:body]['error'] == 'invalid_grant'
70
82
  end
71
83
 
72
84
  def navbar_endpoint
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strongmind-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Belding
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-18 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 3.11.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 3.11.0
97
97
  description: Ruby gem for StrongMind authentication in a strongmind app
98
98
  email:
99
99
  - teambelding@strongmind.com