3232final class Client implements HttpClientInterface
3333{
3434 public const OPTIONS_DEFAULT = [
35+ 'auth_basic ' => null , // array|string - an array containing the username as first value, and optionally the
36+ // password as the second one; or string like username:password - enabling HTTP Basic
37+ // authentication (RFC 7617)
38+ 'auth_bearer ' => null , // string - a token enabling HTTP Bearer authorization (RFC 6750)
3539 'query ' => [], // string[] - associative array of query string values to merge with the request's URL
3640 'headers ' => ['accept ' => ['application/ld+json ' ]], // iterable|string[]|string[][] - headers names provided as keys or as part of values
3741 'body ' => '' , // array|string|resource|\Traversable|\Closure - the callback SHOULD yield a string
3842 'json ' => null , // array|\JsonSerializable - when set, implementations MUST set the "body" option to
3943 // the JSON-encoded value and set the "content-type" headers to a JSON-compatible
4044 'base_uri ' => 'http://example.com ' , // string - the URI to resolve relative URLs, following rules in RFC 3986, section 2
41- 'auth ' => null , // string - a username:password enabling HTTP Basic authentication (RFC 7617)
42- 'bearer ' => null , // string - a token enabling HTTP Bearer authorization (RFC 6750)
4345 ];
4446
4547 use HttpClientTrait;
@@ -83,12 +85,7 @@ public function request(string $method, string $url, array $options = []): Respo
8385 }
8486 }
8587
86- // TODO: remove when https://github.com/symfony/symfony/pull/30547 will be merged
87- if (isset ($ options ['bearer ' ]) && \is_string ($ options ['bearer ' ])) {
88- $ options ['headers ' ]['authorization ' ] = ['Bearer ' .$ options ['bearer ' ]];
89- }
90-
91- $ basic = $ options ['auth ' ] ?? null ;
88+ $ basic = $ options ['auth_basic ' ] ?? null ;
9289 [$ url , $ options ] = $ this ->prepareRequest ($ method , $ url , $ options , self ::OPTIONS_DEFAULT );
9390
9491 $ server = [];
@@ -105,7 +102,7 @@ public function request(string $method, string $url, array $options = []): Respo
105102 }
106103
107104 if ($ basic ) {
108- $ credentials = explode (': ' , $ basic , 2 );
105+ $ credentials = is_array ( $ basic ) ? $ basic : explode (': ' , $ basic , 2 );
109106 $ server ['PHP_AUTH_USER ' ] = $ credentials [0 ];
110107 $ server ['PHP_AUTH_PW ' ] = $ credentials [1 ] ?? '' ;
111108 }
0 commit comments