http->post('oauth2/authorize/token', [ 'code' => $code, 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'redirect_uri' => $redirectUri, 'grant_type' => 'authorization_code', ]); $body = $response->json(); if (!isset($body['access_token'], $body['refresh_token'])) { throw new \RuntimeException('Auth failed: ' . ($body['message'] ?? 'Unknown error')); } return [ 'access_token' => $body['access_token'], 'refresh_token' => $body['refresh_token'], ]; } }