I want to reflect RPCs from the grpc server, but my server requires authentication with Bearer token.
I’ve set the token in the pm.Collection. However it seems, “Before invoke” script does not executed when request reflection.
Everytime the token expires, I need to update the token in collection myself.
How can I make it automatically updates the token when I request reflection to the server?
Here’s my script:
try {
const response = await pm.sendRequest({
url: pm.environment.get("auth_server_url"),
method: "POST",
header: {
'Content-Type': 'application/json',
},
body: {
mode: 'raw',
raw: JSON.stringify({
"api_key": pm.environment.get("api_key"),
"secret": pm.environment.get("api_secret"),
"scope": pm.environment.get("api_scope"),
})
}
});
pm.environment.set("jwt_token", response.text())
console.log("Successfully refreshed JWT")
} catch (err) {
console.error(err);
}