@@ -26,31 +26,38 @@ bootstrap_oauth(Req0, State) ->
26
26
Dependencies = oauth_dependencies (),
27
27
JSContent = import_dependencies (Dependencies ) ++
28
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 ,
33
- {ok , cowboy_req :reply (200 , #{<<" content-type" >> => <<" text/javascript; charset=utf-8" >>}, JSContent , Req0 ), State }.
29
+ set_token_auth (AuthSettings , Req0 ) ++
30
+ export_dependencies (Dependencies ),
31
+ {ok , cowboy_req :reply (200 , #{<<" content-type" >> => <<" text/javascript; charset=utf-8" >>},
32
+ JSContent , Req0 ), State }.
34
33
35
34
set_oauth_settings (AuthSettings ) ->
36
35
JsonAuthSettings = rabbit_json :encode (rabbit_mgmt_format :format_nulls (AuthSettings )),
37
36
[" set_oauth_settings(" , JsonAuthSettings , " );" ].
38
-
39
- set_token_auth (Req0 ) ->
40
- case application : get_env ( rabbitmq_management , oauth_enabled , false ) of
41
- true ->
37
+
38
+ set_token_auth (AuthSettings , Req0 ) ->
39
+ case proplists : get_value ( oauth_enabled , AuthSettings , false ) of
40
+ true ->
42
41
case cowboy_req :parse_header (<<" authorization" >>, Req0 ) of
43
42
{bearer , Token } -> [" set_token_auth('" , Token , " ');" ];
44
43
_ -> []
45
44
end ;
46
- false -> []
45
+ false ->
46
+ []
47
47
end .
48
48
49
49
import_dependencies (Dependencies ) ->
50
50
[" import {" , string :join (Dependencies , " ," ), " } from './helper.js';" ].
51
51
52
52
oauth_dependencies () ->
53
- [" oauth_initialize_if_required" , " hasAnyResourceServerReady" , " oauth_initialize" , " oauth_initiate" , " oauth_initiateLogin" , " oauth_initiateLogout" , " oauth_completeLogin" , " oauth_completeLogout" , " set_oauth_settings" ].
53
+ [" oauth_initialize_if_required" ,
54
+ " hasAnyResourceServerReady" ,
55
+ " oauth_initialize" , " oauth_initiate" ,
56
+ " oauth_initiateLogin" ,
57
+ " oauth_initiateLogout" ,
58
+ " oauth_completeLogin" ,
59
+ " oauth_completeLogout" ,
60
+ " set_oauth_settings" ].
54
61
55
62
export_dependencies (Dependencies ) ->
56
63
[ io_lib :format (" window.~s = ~s ;" , [Dep , Dep ]) || Dep <- Dependencies ].
0 commit comments