oauth; $currentSite = Craft::$app->getSites()->getCurrentSite(); $metadata = [ 'client_id' => $oauth->getClientId($currentSite->handle), 'client_name' => 'Standard.site for Craft CMS', 'client_uri' => rtrim($currentSite->getBaseUrl(), '/'), 'redirect_uris' => [$oauth->getRedirectUri($currentSite->handle)], 'grant_types' => ['authorization_code', 'refresh_token'], 'response_types' => ['code'], 'token_endpoint_auth_method' => 'none', 'scope' => 'atproto transition:generic', 'application_type' => 'web', 'dpop_bound_access_tokens' => true, ]; return $this->asJson($metadata); } /** * OAuth callback from PDS. Exchange code for tokens. */ public function actionCallback(): Response { $request = Craft::$app->getRequest(); $code = $request->getQueryParam('code'); $state = $request->getQueryParam('state'); if (!$code || !$state) { Craft::$app->getSession()->setError('Missing authorization code or state.'); return $this->redirect(\craft\helpers\UrlHelper::cpUrl('standard-site')); } $error = $request->getQueryParam('error'); if ($error) { $description = $request->getQueryParam('error_description', $error); Craft::$app->getSession()->setError("Authorization failed: {$description}"); return $this->redirect(\craft\helpers\UrlHelper::cpUrl('standard-site')); } try { Craft::info("OAuth callback received. code length: " . strlen($code) . ", state: {$state}", __METHOD__); StandardSite::getInstance()->oauth->handleCallback($code, $state); Craft::info("OAuth callback success — tokens stored.", __METHOD__); Craft::$app->getSession()->setNotice('Connected to AT Protocol successfully.'); } catch (\Throwable $e) { Craft::error("OAuth callback failed: {$e->getMessage()}\n{$e->getTraceAsString()}", __METHOD__); Craft::$app->getSession()->setError("Callback failed: {$e->getMessage()}"); } return $this->redirect(\craft\helpers\UrlHelper::cpUrl('standard-site')); } }