Created
May 8, 2023 15:03
-
-
Save maximgorbatyuk/3de739c8630ae88c55106959971ae751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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