@@ -71,18 +71,30 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
7171 throw new InvalidArgumentException (sprintf ('Option "on_progress" must be callable, %s given. ' , \is_object ($ onProgress ) ? \get_class ($ onProgress ) : \gettype ($ onProgress )));
7272 }
7373
74- if (!\is_string ($ options ['auth ' ] ?? '' )) {
75- throw new InvalidArgumentException (sprintf ('Option "auth" must be string, %s given. ' , \gettype ($ options ['auth ' ])));
74+ if (!\is_string ($ options ['auth_basic ' ] ?? '' )) {
75+ throw new InvalidArgumentException (sprintf ('Option "auth_basic" must be string, %s given. ' , \gettype ($ options ['auth_basic ' ])));
76+ }
77+
78+ if (!\is_string ($ options ['auth_bearer ' ] ?? '' )) {
79+ throw new InvalidArgumentException (sprintf ('Option "auth_bearer" must be string, %s given. ' , \gettype ($ options ['auth_bearer ' ])));
80+ }
81+
82+ if (isset ($ options ['auth_basic ' ], $ options ['auth_bearer ' ])) {
83+ throw new InvalidArgumentException ('Define either the "auth_basic" or the "auth_bearer" option, setting both is not supported. ' );
7684 }
7785
7886 if (null !== $ url ) {
7987 // Merge auth with headers
80- if (($ options ['auth ' ] ?? false ) && !($ headers ['authorization ' ] ?? false )) {
81- $ rawHeaders [] = 'authorization: ' .$ headers ['authorization ' ][] = 'Basic ' .base64_encode ($ options ['auth ' ]);
88+ if (($ options ['auth_basic ' ] ?? false ) && !($ headers ['authorization ' ] ?? false )) {
89+ $ rawHeaders [] = 'authorization: ' .$ headers ['authorization ' ][] = 'Basic ' .base64_encode ($ options ['auth_basic ' ]);
90+ }
91+ // Merge bearer with headers
92+ if (($ options ['auth_bearer ' ] ?? false ) && !($ headers ['authorization ' ] ?? false )) {
93+ $ rawHeaders [] = 'authorization: ' .$ headers ['authorization ' ][] = 'Bearer ' .$ options ['auth_bearer ' ];
8294 }
8395
8496 $ options ['raw_headers ' ] = $ rawHeaders ;
85- unset($ options ['auth ' ]);
97+ unset($ options ['auth_basic ' ], $ options [ ' auth_bearer ' ]);
8698
8799 // Parse base URI
88100 if (\is_string ($ options ['base_uri ' ])) {
0 commit comments