@@ -71,18 +71,30 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
71
71
throw new InvalidArgumentException (sprintf ('Option "on_progress" must be callable, %s given. ' , \is_object ($ onProgress ) ? \get_class ($ onProgress ) : \gettype ($ onProgress )));
72
72
}
73
73
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. ' );
76
84
}
77
85
78
86
if (null !== $ url ) {
79
87
// 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 ' ];
82
94
}
83
95
84
96
$ options ['raw_headers ' ] = $ rawHeaders ;
85
- unset($ options ['auth ' ]);
97
+ unset($ options ['auth_basic ' ], $ options [ ' auth_bearer ' ]);
86
98
87
99
// Parse base URI
88
100
if (\is_string ($ options ['base_uri ' ])) {
0 commit comments