@@ -20,31 +20,38 @@ bootstrap_oauth(Req0, State) ->
20
20
Dependencies = oauth_dependencies (),
21
21
JSContent = import_dependencies (Dependencies ) ++
22
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 ,
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 }.
28
27
29
28
set_oauth_settings (AuthSettings ) ->
30
29
JsonAuthSettings = rabbit_json :encode (rabbit_mgmt_format :format_nulls (AuthSettings )),
31
30
[" 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 ->
36
35
case cowboy_req :parse_header (<<" authorization" >>, Req0 ) of
37
36
{bearer , Token } -> [" set_token_auth('" , Token , " ');" ];
38
37
_ -> []
39
38
end ;
40
- false -> []
39
+ false ->
40
+ []
41
41
end .
42
42
43
43
import_dependencies (Dependencies ) ->
44
44
[" import {" , string :join (Dependencies , " ," ), " } from './helper.js';" ].
45
45
46
46
oauth_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" ].
48
55
49
56
export_dependencies (Dependencies ) ->
50
57
[ io_lib :format (" window.~s = ~s ;" , [Dep , Dep ]) || Dep <- Dependencies ].
0 commit comments