bruno icon indicating copy to clipboard operation
bruno copied to clipboard

bru run fails with OAuth2 authorization_code flow while Bruno Desktop works with the same collection

Open dipeshinstanda opened this issue 2 months ago β€’ 9 comments

I have checked the following:

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

This bug is:

  • [x] Making Bruno unusable for me.
  • [ ] Slowing me down but I'm able to continue working.
  • [ ] Annoying.
  • [ ] This feature was working in a previous version but is broken in the current release.

Bruno version

4.2.0

πŸ’» Operating System

Windows

Specific OS Version / Distro

Windows

🐞 Describe the bug

Bruno versions β€’ Bruno Desktop: 4.2.0 β€’ Bruno CLI: 4.1.0 OS β€’ Windows

Example structure: MyBrunoCollection/ β”œβ”€β”€ opencollection.yml β”œβ”€β”€ environments/ β”‚ └── test-env.yml └── Service API/ β”œβ”€β”€ folder.yml <- parent folder-level OAuth2 auth └── Scenario Group/ auth: inherit └── Scenario-01/ auth: inherit β”œβ”€β”€ folder.yml <- child folder in hierarchy auth: inherit β”œβ”€β”€ StartQuote.yml auth: inherit └── GetQuote.yml auth: inherit

OAuth2 authorization_code authentication works in Bruno Desktop, but the same collection fails with 401 Unauthorized when run via bru run in CLI. Desktop opens browser login and completes authentication successfully. CLI does not appear to complete token acquisition for the same auth configuration, and the request is sent without valid authorization. To reproduce

  1. Configure a collection/folder with OAuth2 Authorization Code flow.
  2. Use settings similar to: β€’ authorizationUrl β€’ accessTokenUrl β€’ clientId β€’ scope β€’ callback_url: https://oauth.usebruno.com/callback β€’ autoFetchToken: true
  3. Run successfully in Bruno Desktop.
  4. Run the same request/folder in CLI using bru run.

Example auth config auth: type: oauth2 flow: authorization_code authorizationUrl: "" accessTokenUrl: "" callback_url: "https://oauth.usebruno.com/callback" credentials: clientId: "" placement: body scope: "" pkce: disabled: true tokenConfig: id: credentials placement: header: Bearer source: access_token settings: autoFetchToken: true autoRefreshToken: true

CLI command: bru run "Test Name" --env environment-file -r

Actual behavior CLI run returns 401 Unauthorized.

toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type toBrunoAuth failed: Unsupported auth type

My Test\Step-1 (401 Unauthorized) - 702 ms Tests βœ• Status should be 200 expected 401 to equal 200 βœ• StartQuote response should match body properties expected undefined to equal 'AboutToQuickQuote' My Test\Step-2 (401 Unauthorized) - 672 ms Tests βœ• Status should be 200 expected 401 to equal 200 βœ• response should match body properties expected undefined to equal '543766'

πŸ“Š Execution Summary β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Metric β”‚ Result β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Status β”‚ βœ— FAIL β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Requests β”‚ 2 (2 Failed) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Tests β”‚ 0/4 β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Assertions β”‚ 0/0 β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Duration (ms) β”‚ 2141 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Expected behavior CLI should either: 1. complete OAuth2 Authorization Code token acquisition, or 2. clearly indicate that interactive Authorization Code flow is not supported in CLI.

Notes β€’ The same collection works in Bruno Desktop. β€’ Adding callback_url: https://oauth.usebruno.com/callback allowed Desktop auth to work. β€’ CLI still fails with 401 Unauthorized. β€’ A bearer-token workaround works in CLI, but native authorization_code flow does not. Impact:

This blocks running the same authenticated collection in CI/CLI while it works in Desktop. This blocks running the collection in pipeline

πŸ“ Steps to reproduce

OAuth2 authorization_code authentication works in Bruno Desktop, but the same collection fails with 401 Unauthorized when run via bru run in CLI. Desktop opens browser login and completes authentication successfully. CLI does not appear to complete token acquisition for the same auth configuration, and the request is sent without valid authorization. To reproduce

  1. Configure a collection/folder with OAuth2 Authorization Code flow.
  2. Use settings similar to: β€’ authorizationUrl β€’ accessTokenUrl β€’ clientId β€’ scope β€’ callback_url: https://oauth.usebruno.com/callback β€’ autoFetchToken: true
  3. Run successfully in Bruno Desktop.
  4. Run the same request/folder in CLI using bru run.

Example auth config auth: type: oauth2 flow: authorization_code authorizationUrl: "" accessTokenUrl: "" callback_url: "https://oauth.usebruno.com/callback" credentials: clientId: "" placement: body scope: "" pkce: disabled: true tokenConfig: id: credentials placement: header: Bearer source: access_token settings: autoFetchToken: true autoRefreshToken: true

CLI command: bru run "Test Name" --env environment-file -r

πŸ“ Collection to reproduce

No response

πŸ“· Screenshots/Live demo link

Image

dipeshinstanda avatar Sep 24 '26 10:09 dipeshinstanda

i would like to work on this issue. Can anyone assign me this?

iamrishu11 avatar Sep 24 '26 11:09 iamrishu11

@brunobragaw8t/ @brunohpaiva / @brunograsselli / @sid-bruno / @ved-bruno / @sachin-bruno / @sachin-thakur-bruno / @sanish-bruno / @Gopi-bruno / @gopu-bruno / @naman-bruno / @pooja-bruno / @utkarsh-bruno / @ravindra-bruno / @chirag-bruno @sanish-bruno @sanjaikumar-bruno / @shubh-bruno / @sharan-bruno / @aditya-bruno / @adwait-bruno @arpit-bruno

@iamrishu11 Is interested to work on this issue. Could you please take a look and assign him if everything seems okay

dipeshinstanda avatar Sep 25 '26 09:09 dipeshinstanda

Hi @iamrishu11, you can surely work on this and raise a PR following the contributing guidelines. Once raised we'll review your PR and update you accordingly.

@dipeshinstanda, could you please help us with a screen recording of the OAuth working on the desktop and same time giving an error in CLI?

Rohan-Bruno avatar Sep 25 '26 09:09 Rohan-Bruno

Hey @Rohan-Bruno , just wanted to confirm the intended scope of this issue. Should the CLI actually support completing the OAuth2 Authorization Code flow, or should it instead clearly indicate that interactive Authorization Code authentication is not supported in bru run?

iamrishu11 avatar Sep 25 '26 10:09 iamrishu11

@Rohan-Bruno Please find the requested recording:

https://github.com/user-attachments/assets/96399480-4662-41d6-b3b0-87407ede1207

@iamrishu11 : The CLI should support the OAuth 2.0 Authorization Code Flow. We're already receiving a 401 Unauthorized response, which confirms that authentication is currently not working.

At this point, the issue appears to be related to the authentication flow rather than the API functionality itself. Once the CLI is configured to authenticate correctly using the Authorization Code Flow, we can verify whether there are any additional issues.

dipeshinstanda avatar Sep 25 '26 12:09 dipeshinstanda

Hi @Rohan-Bruno , I’ve opened a PR for this: https://github.com/usebruno/bruno/pull/9375

The PR adds real OAuth 2.0 Authorization Code support to bru run, including:

  • inherited folder-level OAuth2 auth
  • browser-based interactive sign-in
  • PKCE and state validation
  • localhost callback handling with a one-shot loopback listener
  • pasted callback URL fallback for non-local callbacks such as https://oauth.usebruno.com/callback
  • authorization-code exchange and refresh handling
  • in-memory token reuse across requests sharing the same OAuth credentials
  • avoiding repeated sign-in prompts after the same authorization failure
  • clear behavior in non-interactive/headless environments instead of silently sending unauthenticated requests

I also added unit and end-to-end coverage with a mock IdP. The CLI and requests test suites pass, and the requests package builds successfully.

Electron/Desktop behavior is unchanged, and the CLI does not read or reuse Desktop’s OAuth token store.

iamrishu11 avatar Sep 25 '26 15:09 iamrishu11

Hi @dipeshinstanda, thank you for the screen recording! I wanted to check what you’re currently doing as a workaround for this issue.

Rohan-Bruno avatar Sep 30 '26 08:09 Rohan-Bruno

@Rohan-Bruno : Currently, we are just running them only on Bruno desktop. But we want to create a pipeline on azure devops to run them automatically which requires an support on the cli.

dipeshinstanda avatar Sep 30 '26 09:09 dipeshinstanda

Hi @dipeshinstanda, thank you for the details!

So Bruno CLI doesn't support the OAuth2 Authorization Code flow today. That grant needs someone to log in, consent through a browser. CLI is headless so there's no browser to show that screen.

The desktop app can do it because it opens a browser window, captures the token, and stores it locally, but the CLI runs as a separate process and doesn't read the desktop app's stored token.

For CLI/CI runs, OAuth2 works with the grants that don't need a browser which is Client Credentials and Password. If Authorization Code is required in automation, the usual workaround is to obtain a token out-of-band and pass it in (e.g. as a bearer token / variable).

About toBrunoAuth failed: Unsupported auth type: These aren't related to the 401. When you run bru run, the CLI first reads every file in your collection, not just the folder you're running. This warning appears when a file has an auth value Bruno doesn't recognize. Bruno then treats that file as having no auth and carries on. The desktop app reads the same files but doesn't display this warning, which is why you only see it in the terminal.

Supported values are:

  • auth: inherit
  • auth: with a type: of oauth2, bearer, basic, apikey, digest, ntlm, awsv4, wsse, oauth1 or akamai-edgegrid
  • no auth line at all, which means no auth

Values are case-sensitive, so things like auth: Inherit, auth: none will trigger the warning. Fixing those entries in your other folders and requests should clear the messages.

Rohan-Bruno avatar Oct 01 '26 08:10 Rohan-Bruno