I need to automate some tests in postman, at the moment my solution is manual.
I login to the site i’m testing and check the developer tools in chrome and get the bearer token.
and copy it to the environment variable.
Is there a way to extract the bearer token programatically?
I managed to get an access token by using the script below, i’m still having an issue. The requests
that uses the global variable jwttoken. fails to authenticate. i get Bearer error=“invalid_token”,
error_description=“The issuer is invalid”
var options = {
method: 'POST',
url: pm.variables.get('auth0_url'),
header: {
"Content-Type": "application/json"
},
body: {
mode: 'raw',
raw: JSON.stringify({
client_id: pm.variables.get('client_id'),
client_secret: pm.variables.get('client_secret'),
audience: pm.variables.get('web_url'),
grant_type: 'client_credentials'
})
}
}
pm.sendRequest(options, function (error, response, body) {
if (error) throw new Error(error);
var json = JSON.parse(response.text());
pm.globals.set("jwttoken",json['access_token'])
});