Open
Description
Описание
Summary
The codeVerifier
parameter passed to VKID.Config.init
is not used by the SDK. The SDK generates a new codeVerifier
token every time, and it does not save it in cookies as it should, according to the source code. As a result, when I call VKID.Auth.exchangeCode
, it receives the error Invalid code_challenge
.
Workaround
Pass codeChallenge
to VKID.Config.init
instead of the codeVerifier
parameter, and save codeVerifier
somewhere yourself.
Шаги воспроизведения
Steps
According to the documentation to get access and refresh tokens it's enough to do the following
- Init VKID SDK.
VKID.Config.init({
app: 00000000, // Идентификатор приложения.
redirectUrl: 'http://mydomen/vkAuth', // Адрес для перехода после авторизации.
state: 'dj11fnsadjsd82', // Произвольная строка состояния приложения.
codeVerifier: 'FGH767Gd65sdkjsaju32jdf243huifskdfh32fjJs73fhGgy3Dfgsd2'
scope: 'email phone', // Список прав доступа, которые нужны приложению.
mode: VKID.ConfigAuthMode.Redirect, // По умолчанию авторизация открывается в новой вкладке.
});
- Init OneTab
const oneTapTmp = new VKID.OneTap();
// Получение контейнера из разметки.
const container = document.getElementById('VkIdSdkOneTap');
if (container) {
// Отрисовка кнопки в контейнере с именем приложения APP_NAME, светлой темой и на русском языке.
oneTapTmp
.render({
container: container,
scheme: VKID.Scheme.LIGHT,
lang: VKID.Languages.RUS
})
.on(VKID.WidgetEvents.ERROR, handleError); // handleError — какой-либо обработчик ошибки.
}
- Exchange code
const code = query.get('code')!;
const device_id = query.get('device_id')!;
const state = query.get('state');
(async function () {
const authTokens = await VKID.Auth.exchangeCode(responseCode, device_id);
console.log('Access Token:', authTokens.access_token);
const userInfo = await VKID.Auth.userInfo(authTokens.access_token);
})();
Result
Error received
{
"error": "invalid_request",
"error_description": "invalid code_challenge",
"state": "dj29fnsadjsd82"
}
Версия vkid/sdk
2.1.0
В каких браузерах воспроизводится проблема?
Chrome
Ожидаемое поведение
Refresh, access, and other tokens are received.
Скриншоты
Пример с воспроизведением
No response