Сниппеты для копирования

Подставьте свои CLIENT_ID и секрет после регистрации приложения.

cURL: обмен code на token

curl -s -X POST "https://zippy-chat.ru/oauth/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code&code=CODE&redirect_uri=https://zippy-chat.ru/oauth/dev-portal/callback&client_id=CLIENT_ID&client_secret=SECRET"

JavaScript: открыть авторизацию (новое окно)

const u = new URL("https://zippy-chat.ru/oauth/authorize");
u.searchParams.set("response_type", "code");
u.searchParams.set("client_id", "CLIENT_ID");
u.searchParams.set("redirect_uri", "https://zippy-chat.ru/oauth/dev-portal/callback");
u.searchParams.set("state", crypto.randomUUID());
window.location.href = u.toString();

PHP: userinfo

$ch = curl_init("https://zippy-chat.ru/oauth/userinfo");
curl_setopt_array($ch, [
  CURLOPT_HTTPHEADER => ["Authorization: Bearer " . $accessToken],
  CURLOPT_RETURNTRANSFER => true,
]);
$json = curl_exec($ch);

iframe: виджет сессии на .dev

<iframe src="https://dev.zippy-chat.ru/sandbox/widget" style="width:100%;min-height:160px;border:0;border-radius:14px" title="ZIPPY sandbox"></iframe>

fetch: userinfo из браузера (только если CORS разрешён на проде)

Обычно userinfo вызывают с сервера, чтобы не светить токен в JS. Ниже — шаблон для отладки.

fetch("https://zippy-chat.ru/oauth/userinfo", {
  headers: { Authorization: "Bearer " + accessToken }
}).then(r => r.json()).then(console.log);

JSON: тело ответа userinfo (пример)

{
  "sub": "123",
  "name": "Имя",
  "email": "u@example.com"
}