The auth0 API doesn’t work and I need help.
Postman script:
const auth0Domain = pm.environment.get('AUTH0_DOMAIN');
const clientId = pm.environment.get('AUTH0_CLIENT_ID');
const clientSecret = pm.environment.get('AUTH0_CLIENT_SECRET');
const audience = pm.environment.get('AUTH0_AUDIENCE');
const tokenUrl = `https://${auth0Domain}/oauth/token`;
const username = pm.environment.get('USER_EMAIL');
const password = pm.environment.get('USER_PASSWORD');
console.log(
{
auth0Domain, clientId, clientSecret, audience, tokenUrl, username, password
}
)
const getTokenRequest = {
method: 'POST',
url: tokenUrl,
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: 'grant_type', value: 'password'},
{key: 'client_id', value: clientId},
{key: 'client_secret', value: clientSecret},
{key: 'username', value: username},
{key: 'password', value: password},
{key: 'audience', value: audience},
{key: 'scope', value: 'openid profile email'}
]
}
};
pm.sendRequest(getTokenRequest, (err, response) => {
if (err) {
console.error(err);
} else {
const jsonResponse = response.json();
const newAccessToken = jsonResponse.access_token;
pm.environment.set('ACCESS_TOKEN', newAccessToken);
console.log('New access token set:', newAccessToken);
}
});
error
{"error":"invalid_request","error_description":"invalid audience specified for password grant exchange"}
Everything in auth0 are configured but the API doesn’t work. the tenant is configured exact same as different tenant where the script works. what is the thing could be wrong?