@@ -24,24 +24,18 @@ init(Req0, State) ->
24
24
bootstrap_oauth (Req0 , State ) ->
25
25
AuthSettings = rabbit_mgmt_wm_auth :authSettings (),
26
26
Dependencies = oauth_dependencies (),
27
- JSContent = case proplists :get_value (oauth_enabled , AuthSettings , false ) of
28
- false -> declare_oauth_initialize_if_required (AuthSettings );
29
- true -> import_dependencies (Dependencies ) ++
30
- declare_oauth_initialize_if_required (AuthSettings ) ++
31
- set_token_auth (Req0 ) ++
32
- export_dependencies (Dependencies )
33
-
34
- end ++ export_dependencies ([" oauth_initialize_if_required" ]),
27
+ JSContent = import_dependencies (Dependencies ) ++
28
+ set_oauth_settings (AuthSettings ) ++
29
+ case proplists :get_value (oauth_enabled , AuthSettings , false ) of
30
+ true -> set_token_auth (Req0 ) ++ export_dependencies (oauth_dependencies ());
31
+ false -> export_dependencies ([" oauth_initialize_if_required" , " set_oauth_settings" ])
32
+ end ,
35
33
{ok , cowboy_req :reply (200 , #{<<" content-type" >> => <<" text/javascript; charset=utf-8" >>}, JSContent , Req0 ), State }.
36
34
37
- declare_oauth_initialize_if_required (AuthSettings ) ->
35
+ set_oauth_settings (AuthSettings ) ->
38
36
case proplists :get_value (oauth_enabled , AuthSettings , false ) of
39
- true -> [" export default function oauth_initialize_if_required(state) { " ,
40
- " let oauth = oauth_initialize(" , rabbit_json :encode (rabbit_mgmt_format :format_nulls (AuthSettings )), " ); " ,
41
- " if (!oauth.enabled) return oauth;"
42
- " switch (state) { case 'login-callback': oauth_completeLogin(); break; case 'logout-callback': oauth_completeLogout(); break; default: oauth = oauth_initiate(oauth);}" ,
43
- " return oauth; }" ];
44
- false -> [" export default function oauth_initialize_if_required(state) { return {oauth_enabled: false}; }" ]
37
+ true -> [" set_oauth_settings(" , rabbit_json :encode (rabbit_mgmt_format :format_nulls (AuthSettings )), " ); " ];
38
+ false -> [" set_oauth_settings({oauth_enabled: false});" ]
45
39
end .
46
40
47
41
set_token_auth (Req0 ) ->
@@ -58,7 +52,7 @@ import_dependencies(Dependencies) ->
58
52
[" import {" , string :join (Dependencies , " ," ), " } from './helper.js';" ].
59
53
60
54
oauth_dependencies () ->
61
- [" hasAnyResourceServerReady" , " oauth_initialize" , " oauth_initiate" , " oauth_initiateLogin" , " oauth_initiateLogout" , " oauth_completeLogin" , " oauth_completeLogout" ].
55
+ [" oauth_initialize_if_required " , " hasAnyResourceServerReady" , " oauth_initialize" , " oauth_initiate" , " oauth_initiateLogin" , " oauth_initiateLogout" , " oauth_completeLogin" , " oauth_completeLogout" , " set_oauth_settings " ].
62
56
63
57
export_dependencies (Dependencies ) ->
64
58
[ io_lib :format (" window.~s = ~s ;" , [Dep , Dep ]) || Dep <- Dependencies ].
0 commit comments