fix and update
This commit is contained in:
@@ -158,17 +158,45 @@
|
||||
return requestFedCM(resolved.value);
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (global.console && typeof global.console.warn === 'function') {
|
||||
global.console.warn(
|
||||
'[MVK ID] FedCM недоступен:',
|
||||
if (global.console && typeof global.console.debug === 'function') {
|
||||
global.console.debug(
|
||||
'[MVK ID] FedCM недоступен (будет использован popup):',
|
||||
error,
|
||||
'Проверьте публичный URL IdP в data-idp-url и доступность /.well-known/web-identity на домене IdP (не /idp-api/.well-known).'
|
||||
'Для One Tap без popup: примите SSL для корневого домена IdP (например idpmvk.lpr) и проверьте /.well-known/web-identity.'
|
||||
);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
function exchangeAuthorizationCode(idpApiBase, clientId, clientSecret, code, redirectUri) {
|
||||
if (!code || !clientId || !clientSecret) {
|
||||
return Promise.reject(new Error('Для обмена code нужны clientId, clientSecret и authorization code'));
|
||||
}
|
||||
var body = new URLSearchParams();
|
||||
body.set('grant_type', 'authorization_code');
|
||||
body.set('code', code);
|
||||
body.set('client_id', clientId);
|
||||
body.set('client_secret', clientSecret);
|
||||
body.set('redirect_uri', redirectUri);
|
||||
return global.fetch(trimSlash(idpApiBase) + '/oauth/token', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: body.toString()
|
||||
}).then(function (response) {
|
||||
return response.json().then(function (payload) {
|
||||
if (!response.ok) {
|
||||
var message = payload && (payload.message || payload.error_description || payload.error);
|
||||
throw new Error(message || 'Не удалось обменять authorization code');
|
||||
}
|
||||
return payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var SIZE_PRESETS = {
|
||||
s: { height: 32, font: 13, padX: 12, gap: 8, badge: 20, radius: 16 },
|
||||
m: { height: 40, font: 14, padX: 16, gap: 10, badge: 24, radius: 20 },
|
||||
@@ -406,6 +434,8 @@
|
||||
dispatchSuccess(
|
||||
{
|
||||
token: result.token,
|
||||
idToken: result.token,
|
||||
grantType: 'id_token',
|
||||
method: 'fedcm'
|
||||
},
|
||||
script
|
||||
@@ -420,11 +450,14 @@
|
||||
openPopup(popupUrl, frontendBase, function (payload) {
|
||||
dispatchSuccess(
|
||||
{
|
||||
token: payload.token,
|
||||
accessToken: payload.accessToken,
|
||||
idToken: payload.idToken,
|
||||
refreshToken: payload.refreshToken,
|
||||
code: payload.code,
|
||||
state: payload.state,
|
||||
grantType: payload.grantType || (payload.code ? 'authorization_code' : undefined),
|
||||
idToken: payload.idToken,
|
||||
accessToken: payload.accessToken,
|
||||
refreshToken: payload.refreshToken,
|
||||
tokenEndpoint: trimSlash(idpApiBase) + '/oauth/token',
|
||||
redirectUri: redirectUri,
|
||||
method: 'popup'
|
||||
},
|
||||
script
|
||||
@@ -439,6 +472,7 @@
|
||||
global.LendryIdOneTap = {
|
||||
init: initOneTap,
|
||||
loginWithFedCM: loginWithFedCM,
|
||||
exchangeAuthorizationCode: exchangeAuthorizationCode,
|
||||
MESSAGE_TYPE: MESSAGE_TYPE
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user