@@ -28,6 +28,7 @@ public function __construct(
2828 protected string $ baseUrl ,
2929 protected string $ tokenRequestPath ,
3030 protected array $ authenticationParams ,
31+ protected string $ tokenRequestContentType = 'application/json ' ,
3132 ) {
3233 }
3334
@@ -74,8 +75,19 @@ protected function updateToken(RequestInterface $request, callable $method): OAu
7475
7576 protected function createTokenRequest (): RequestInterface
7677 {
77- return $ this ->requestFactory ->createRequest ('POST ' , $ this ->baseUrl .$ this ->tokenRequestPath )
78- ->withHeader ('Content-Type ' , 'application/x-www-form-urlencoded ' )
79- ->withBody (Stream::create (http_build_query ($ this ->authenticationParams )));
78+ $ tokenRequest = $ this ->requestFactory ->createRequest ('POST ' , $ this ->baseUrl .$ this ->tokenRequestPath )
79+ ->withHeader ('Content-Type ' , $ this ->tokenRequestContentType );
80+
81+ if ('application/x-www-form-urlencoded ' === $ this ->tokenRequestContentType ) {
82+ $ content = http_build_query ($ this ->authenticationParams );
83+ } elseif ('application/json ' === $ this ->tokenRequestContentType ) {
84+ $ content = json_encode ($ this ->authenticationParams , JSON_THROW_ON_ERROR );
85+ } else {
86+ throw new \UnexpectedValueException (
87+ "Unsupported token request content type {$ this ->tokenRequestContentType }"
88+ );
89+ }
90+
91+ return $ tokenRequest ->withBody (Stream::create ($ content ));
8092 }
8193}
0 commit comments