@@ -20,31 +20,38 @@ bootstrap_oauth(Req0, State) ->
2020 Dependencies = oauth_dependencies (),
2121 JSContent = import_dependencies (Dependencies ) ++
2222 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 ,
27- {ok , cowboy_req :reply (200 , #{<<" content-type" >> => <<" text/javascript; charset=utf-8" >>}, JSContent , Req0 ), State }.
23+ set_token_auth (AuthSettings , Req0 ) ++
24+ export_dependencies (Dependencies ),
25+ {ok , cowboy_req :reply (200 , #{<<" content-type" >> => <<" text/javascript; charset=utf-8" >>},
26+ JSContent , Req0 ), State }.
2827
2928set_oauth_settings (AuthSettings ) ->
3029 JsonAuthSettings = rabbit_json :encode (rabbit_mgmt_format :format_nulls (AuthSettings )),
3130 [" set_oauth_settings(" , JsonAuthSettings , " );" ].
32-
33- set_token_auth (Req0 ) ->
34- case application : get_env ( rabbitmq_management , oauth_enabled , false ) of
35- true ->
31+
32+ set_token_auth (AuthSettings , Req0 ) ->
33+ case proplists : get_value ( oauth_enabled , AuthSettings , false ) of
34+ true ->
3635 case cowboy_req :parse_header (<<" authorization" >>, Req0 ) of
3736 {bearer , Token } -> [" set_token_auth('" , Token , " ');" ];
3837 _ -> []
3938 end ;
40- false -> []
39+ false ->
40+ []
4141 end .
4242
4343import_dependencies (Dependencies ) ->
4444 [" import {" , string :join (Dependencies , " ," ), " } from './helper.js';" ].
4545
4646oauth_dependencies () ->
47- [" oauth_initialize_if_required" , " hasAnyResourceServerReady" , " oauth_initialize" , " oauth_initiate" , " oauth_initiateLogin" , " oauth_initiateLogout" , " oauth_completeLogin" , " oauth_completeLogout" , " set_oauth_settings" ].
47+ [" oauth_initialize_if_required" ,
48+ " hasAnyResourceServerReady" ,
49+ " oauth_initialize" , " oauth_initiate" ,
50+ " oauth_initiateLogin" ,
51+ " oauth_initiateLogout" ,
52+ " oauth_completeLogin" ,
53+ " oauth_completeLogout" ,
54+ " set_oauth_settings" ].
4855
4956export_dependencies (Dependencies ) ->
5057 [ io_lib :format (" window.~s = ~s ;" , [Dep , Dep ]) || Dep <- Dependencies ].
0 commit comments