strongmind-auth 1.1.1 → 1.1.56

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: 0234d7b4cfe4a3a5d738c6ef9af96622f348ca47b39d9b76ff971b6ebc0bfa8f
4
- data.tar.gz: 8ca75096b6b9ed3082f03e4e6a48f9e98f43366fdfc4fdfce72fe3d69c8e0463
3
+ metadata.gz: 6a82e9ae38bf108b49f1cf443aa2ae67c0a14c89c8aed7681e436aaa950ee67b
4
+ data.tar.gz: e033f56ebe05a573eaa27b1b069fea79e992ac885c54aea70793cb846fe2059c
5
5
  SHA512:
6
- metadata.gz: b8cf1a51d8ebbb13566a382ede82a001284123efc5544d97e71c487efffea08f81bace84f65742eb19f1dbbd7b312187e754dcead6e9e9a5d7f6ee44437285c9
7
- data.tar.gz: 619659baf8e51ffd5daafcea330840ce240c0b072856978b491d5f43d2f4f2d0161f9bfdfdf0e9de356ec8383440d1216666acf17e5a4c34c9a804bd29a9b0e7
6
+ metadata.gz: bd99910a06be468290a58282c524a9f813c2fc9c629adbf995a16dd4f187606257770e3a0414bcea7550ed9ba358e81340aac54d851e1427803519928e00f458
7
+ data.tar.gz: f2a8a5da24794639a83f0ba538a59eb9f9c81d9c0946a89d9e2876f25d0caefa225015e6e896395cbd2801b62040db87e59e87b5a2ab65554fbbb6c659c6dd14
@@ -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)
@@ -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.1"
3
+ VERSION = "1.1.56"
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.1
4
+ version: 1.1.56
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-19 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