1313 merge_openid_configuration /2 ,
1414 merge_oauth_provider /2 ,
1515 extract_ssl_options_as_list /1 ,
16- format_ssl_options /1 , format_oauth_provider /1 , format_oauth_provider_id /1
16+ format_ssl_options /1 , format_oauth_provider /1 , format_oauth_provider_id /1 ,
17+ extract_proxy_options_from_url /1
1718 ]).
1819
1920-include (" oauth2_client.hrl" ).
@@ -29,8 +30,9 @@ get_access_token(OAuthProvider, Request) ->
2930 Type = ? CONTENT_URLENCODED ,
3031 Body = build_access_token_request_body (Request ),
3132 HTTPOptions = get_ssl_options_if_any (OAuthProvider ) ++
32- get_timeout_of_default (Request # access_token_request .timeout ),
33- Options = [],
33+ get_timeout_of_default (Request # access_token_request .timeout ) ++
34+ get_proxy_auth_if_any (OAuthProvider # oauth_provider .proxy_options ),
35+ Options = get_proxy_if_any (OAuthProvider # oauth_provider .proxy_options ),
3436 Response = httpc :request (post , {URL , Header , Type , Body }, HTTPOptions , Options ),
3537 parse_access_token_response (Response ).
3638
@@ -43,8 +45,9 @@ refresh_access_token(OAuthProvider, Request) ->
4345 Type = ? CONTENT_URLENCODED ,
4446 Body = build_refresh_token_request_body (Request ),
4547 HTTPOptions = get_ssl_options_if_any (OAuthProvider ) ++
46- get_timeout_of_default (Request # refresh_token_request .timeout ),
47- Options = [],
48+ get_timeout_of_default (Request # refresh_token_request .timeout ) ++
49+ get_proxy_auth_if_any (OAuthProvider # oauth_provider .proxy_options ),
50+ Options = get_proxy_if_any (OAuthProvider # oauth_provider .proxy_options ),
4851 Response = httpc :request (post , {URL , Header , Type , Body }, HTTPOptions , Options ),
4952 parse_access_token_response (Response ).
5053
@@ -96,11 +99,12 @@ drop_trailing_path_separator(Path) when is_list(Path) ->
9699-spec get_openid_configuration (DiscoveryEndpoint :: uri_string :uri_string (),
97100 ssl :tls_option () | [], proxy_options () | undefined ) ->
98101 {ok , openid_configuration ()} | {error , term ()}.
99- get_openid_configuration (DiscoverEndpoint , TLSOptions , _ProxyOptions ) ->
102+ get_openid_configuration (DiscoverEndpoint , TLSOptions , ProxyOptions ) ->
100103 rabbit_log :debug (" get_openid_configuration from ~p (~p )" , [DiscoverEndpoint ,
101104 format_ssl_options (TLSOptions )]),
102- Options = [],
103- Response = httpc :request (get , {DiscoverEndpoint , []}, TLSOptions , Options ),
105+ Options = get_proxy_if_any (ProxyOptions ),
106+ Response = httpc :request (get , {DiscoverEndpoint , []},
107+ TLSOptions ++ get_proxy_auth_if_any (ProxyOptions ), Options ),
104108 parse_openid_configuration_response (Response ).
105109
106110-spec merge_openid_configuration (openid_configuration (), oauth_provider ()) ->
@@ -401,13 +405,28 @@ lookup_root_oauth_provider() ->
401405 proxy_options = extract_proxy_options (Map )
402406 }.
403407
404- -spec extract_proxy_options (#{atom () => any ()}|list ()) -> proxy_options ().
408+ -spec extract_proxy_options_from_url (list ()|binary ()) -> proxy_options ().
409+ extract_proxy_options_from_url (URL ) when is_binary (URL ) ->
410+ extract_proxy_options_from_url (binary_to_list (URL ));
411+ extract_proxy_options_from_url (URL ) when is_list (URL ) ->
412+ Parsed = uri_string :parse (URL ),
413+ # proxy_options {
414+ https =
415+ case maps :get (" scheme" , Parsed , " http" ) of
416+ " http" -> false ;
417+ " https" -> true
418+ end ,
419+ hostname = maps :get (" host" , Parsed , undefined ),
420+ port = maps :get (" port" , Parsed , undefined )
421+ }.
422+
423+ -spec extract_proxy_options (#{atom () => any ()}|list ()) -> proxy_options () | undefined .
405424extract_proxy_options (List ) when is_list (List ) ->
406425 case proplists :get_value (proxy , List , undefined ) of
407426 undefined -> undefined ;
408427 URL ->
409- # proxy_options {
410- proxy = URL ,
428+ Options = extract_proxy_options_from_url ( URL ),
429+ Options # proxy_options {
411430 username = proplists :get_value (proxy_username , List , undefined ),
412431 password = proplists :get_value (proxy_password , List , undefined )
413432 }
@@ -416,8 +435,8 @@ extract_proxy_options(Map) ->
416435 case maps :get (proxy , Map , undefined ) of
417436 undefined -> undefined ;
418437 URL ->
419- # proxy_options {
420- proxy = URL ,
438+ Options = extract_proxy_options_from_url ( URL ),
439+ Options # proxy_options {
421440 username = maps :get (proxy_username , Map , undefined ),
422441 password = maps :get (proxy_password , Map , undefined )
423442 }
@@ -559,6 +578,30 @@ get_timeout_of_default(Timeout) ->
559578 Timeout -> [{timeout , Timeout }]
560579 end .
561580
581+ get_proxy_if_any (ProxyOptions ) ->
582+ case ProxyOptions of
583+ undefined ->
584+ [];
585+ Proxy ->
586+ P = {Proxy # proxy_options .hostname , Proxy # proxy_options .port },
587+ case Proxy # proxy_options .https of
588+ true -> [{https_proxy , P }];
589+ false -> [{proxy , P }]
590+ end
591+ end .
592+
593+ get_proxy_auth_if_any (ProxyOptions ) ->
594+ case ProxyOptions of
595+ undefined ->
596+ [];
597+ Proxy ->
598+ case {Proxy # proxy_options .username , Proxy # proxy_options .password } of
599+ {undefined , _ } -> [];
600+ {_ , undefined } -> [];
601+ {_ , _ } = Auth -> [{proxy_auth , Auth }]
602+ end
603+ end .
604+
562605is_json (? CONTENT_JSON ) -> true ;
563606is_json (_ ) -> false .
564607
@@ -654,14 +697,16 @@ format_ssl_options(TlsOptions) ->
654697 proplists :get_value (cacertfile , TlsOptions ),
655698 CaCertsCount ])).
656699
657- -spec format_proxy_options (proxy_options ()) -> string ().
700+ -spec format_proxy_options (proxy_options ()| undefined ) -> string ().
658701format_proxy_options (undefined ) ->
659702 lists :flatten (io_lib :format (" {no proxy}" , []));
660703
661704format_proxy_options (ProxyOptions ) ->
662- lists :flatten (io_lib :format (" {proxy : ~p , username: ~p , " ++
705+ lists :flatten (io_lib :format (" {https: ~p , hostname: ~p , port : ~p , username: ~p , " ++
663706 " password: ~p }" , [
664- ProxyOptions # proxy_options .proxy ,
707+ ProxyOptions # proxy_options .https ,
708+ ProxyOptions # proxy_options .hostname ,
709+ ProxyOptions # proxy_options .port ,
665710 ProxyOptions # proxy_options .username ,
666711 ProxyOptions # proxy_options .password ])).
667712
0 commit comments