Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth2 token variable cannot be fetched through getVar #4435

Open
2 of 4 tasks
tomdracz opened this issue Apr 4, 2025 · 1 comment
Open
2 of 4 tasks

Oauth2 token variable cannot be fetched through getVar #4435

tomdracz opened this issue Apr 4, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@tomdracz
Copy link

tomdracz commented Apr 4, 2025

I have checked the following:

  • I have searched existing issues and found nothing related to my issue.

This bug is:

  • making Bruno unusable for me
  • slowing me down but I'm able to continue working
  • annoying

Bruno version

2.0.1

Operating System

MacOS Sequoia

Describe the bug

I'm trying to migrate to the new OAuth2 handling introduced in Bruno version 2. So far, so good.

Facing a problem though with trying to reference the access token in pre-request vars or script using bru.getVar

It seems like even though the variable is being recognised as set, it cannot be referenced due to checks here

setVar(key, value) {
if (!key) {
throw new Error('Creating a variable without specifying a name is not allowed.');
}
if (variableNameRegex.test(key) === false) {
throw new Error(
`Variable name: "${key}" contains invalid characters!` +
' Names must only contain alpha-numeric characters, "-", "_", "."'
);
}
this.runtimeVariables[key] = value;
}
getVar(key) {
if (variableNameRegex.test(key) === false) {
throw new Error(
`Variable name: "${key}" contains invalid characters!` +
' Names must only contain alpha-numeric characters, "-", "_", "."'
);
}
return this._interpolate(this.runtimeVariables[key]);
}
that validate variable name through Regex.

Happens both when I set the var in pre-Request through GUI to alias it or try referencing directly through bru.getVar('$oauth2.credentials.access_token')

Is there any other way to access the fetched token from the collection and/or request using getVar methods?

.bru file to reproduce the bug

No response

Screenshots/Live demo link

Image
@tomdracz tomdracz added the bug Something isn't working label Apr 4, 2025
@anusree-bruno anusree-bruno self-assigned this Apr 4, 2025
@anusree-bruno
Copy link
Collaborator

anusree-bruno commented Apr 7, 2025

This is a separate api you can access the token using

bru.getOauth2CredentialVar('$oauth2.<Token ID>.access_token')

We will update the documentation to reflect the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants