Skip to content

Oauth2 token variable cannot be fetched through getVar #4435

Closed
@tomdracz

Description

@tomdracz

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions