Hallo,
für mein Unternehmen musste ich diese Funktion aus unserem Node.js-Backend nutzen. Hier ist eine Referenzimplementierung in JavaScript mit Node.js’ crypto und Buffer, falls jemand interessiert ist:
Hinweis:
Zur Konsistenz verwende ich die gleichen Variablenwerte wie in der PHP-Implementierung.
Richten Sie Ihre API-Anmeldeinformationen und Ihren SSO-geheimen Schlüssel ein
const apiKey = '4fe83002bb5fba8c9a61a65e5b4b0a3cf8233b0e4ccafc85ebd6607abab4651a';
const apiUser = 'system';
const connectSecret = 'jdhb19*Xh3!nu(#k';
Richten Sie die SSO-Parameter ein
const ssoRecord = new URLSearchParams({
external_id: 1,
email: 'bob@example.com',
username: 'bob',
add_groups: 'eurorack',
require_activation: true,
}).toString();
const ssoPayload = Buffer.from(ssoRecord, 'utf8').toString('base64');
const signature = crypto.createHmac('sha256', connectSecret).update(ssoPayload).digest('hex');
Senden Sie die POST-Anfrage
const updatedUser = await fetch({ // oder axios
method: 'POST',
url: 'https://forum.example.com/admin/users/sync_sso',
headers: {
'Api-Key': apiKey,
'Api-Username': apiUser,
'Content-Type': 'application/json',
},
body: JSON.stringify({
sso: ssoPayload,
sig: signature,
})
}).then((response) => response.json());