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