Преглед изворни кода

fix(oidc): Avoid crashes and avoid deleting jwks on update

firest пре 1 година
родитељ
комит
b0e3e405cf

+ 6 - 2
apps/emqx_dashboard_sso/src/emqx_dashboard_sso_oidc.erl

@@ -181,12 +181,16 @@ create(#{name_var := NameVar} = Config) ->
     end.
 
 update(Config, State) ->
-    destroy(State),
+    destroy(State, false),
     create(Config).
 
 destroy(State) ->
+    destroy(State, true).
+
+destroy(State, TryDelete) ->
     emqx_dashboard_sso_oidc_session:stop(),
-    try_delete_jwks_file(State).
+    _ = TryDelete andalso try_delete_jwks_file(State),
+    ok.
 
 -dialyzer({nowarn_function, login/2}).
 login(

+ 6 - 1
apps/emqx_dashboard_sso/src/emqx_dashboard_sso_oidc_session.erl

@@ -35,6 +35,8 @@
 
 -define(DEFAULT_RANDOM_LEN, 32).
 -define(NOW, erlang:system_time(millisecond)).
+-define(BACKOFF_MIN, 5000).
+-define(BACKOFF_MAX, 10000).
 
 %%------------------------------------------------------------------------------
 %% API
@@ -49,7 +51,10 @@ start(Name, #{issuer := Issuer, session_expiry := SessionExpiry0}) ->
             [
                 #{
                     issuer => Issuer,
-                    name => {local, Name}
+                    name => {local, Name},
+                    backoff_min => ?BACKOFF_MIN,
+                    backoff_max => ?BACKOFF_MAX,
+                    backoff_type => random
                 }
             ]
         )