'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(),
'redirect_uri' => $this->getCallbackUrl(),
- 'code' => $_GET['code'],
+ 'code' => $code,
- ], '', '&', \PHP_QUERY_RFC1738));
+ ];
+
+ if ($this->usePkce()) {
+ if (!($verifier = WCF::getSession()->getVar(self::PKCE))) {
+ throw new StateValidationException('Missing PKCE verifier in session');
+ }
+
+ $payload['code_verifier'] = $verifier;
+ }
+
+ $request = new Request('POST', $this->getTokenEndpoint(), [
+ 'Accept' => 'application/json',
+ 'Content-Type' => 'application/x-www-form-urlencoded',
+ ], \http_build_query($payload, '', '&', \PHP_QUERY_RFC1738));
try {
$response = $this->getHttpClient()->send($request);