My question:
How can I access a Collection’s Authorization details from the Collection’s Pre-request Script?
Details:
Specifically, in my collection I have defined OAuth 2.0 with a Bearer token in the collection’s Authorization tab. I’d like to set an environment variable based on a claim in the JWT in a Pre-request Script, but this doesn’t seem possible.
I’ve already tried:
In the Collection’s Pre-Request Script I’ve tried the following:
- Calling
pm.request.getHeaders()
returns an empty object. I thought if I had access to the request headers, I could read the Authorization header and get access to the token that way, but the headers are empty at that point. - Calling
pm.request.auth
returns undefined. I thought that might have given me access to the oauth2 bearer token but since it returns undefined that doesn’t help.
This seems like it should be a fairly common use case. Any help would be appreciated. Thanks!