Skip to content

Instantly share code, notes, and snippets.

@maximgorbatyuk
Created May 8, 2023 15:03
Show Gist options
  • Save maximgorbatyuk/3de739c8630ae88c55106959971ae751 to your computer and use it in GitHub Desktop.
Save maximgorbatyuk/3de739c8630ae88c55106959971ae751 to your computer and use it in GitHub Desktop.
const axios = require('axios');
const getData = async function(clientId) {
const options = {
method: 'get',
url: 'https://api.example.net/some-data/' + clientId,
headers: {
'Content-Type': 'application/json',
'x-api-version': '3'
}
};
const response = await axios.request(options);
// Стоит проверить статус ответа и валидность данных
console.log(response.status);
console.log(response.data);
// Здесь мы берем данные из ответа бэкенда
return response.data.permissions
}
// Код коллбека Auth0, создаваемый автоматически
exports.onExecuteCredentialsExchange = async (event, api) => {
const clientId = event.client.client_id;
const permissions = await getAccessData(clientId);
// Записываем данные в токен
const namespace = 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims';
api.accessToken.setCustomClaim(namespace + "/permissions", permissions);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment