# OAuth isn't passing to the request in CLI

**URL:** <https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057>\
**Category:** Help Hub\
**Tags:** oauth2, cli\
**Created:** [January 29, 2024, 9:06pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057 "2024-01-29T21:06:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nategerman](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nategerman](https://community.postman.com/u/nategerman)\
**Post date:** [January 29, 2024, 9:06pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/1 "2024-01-29T21:06:53Z")

</div>

I am attempting to run a request in postman cli, but I continually receive a 401 Unauthorized response. The request works consistently when run through the postman app, but fails every time when run through the CLI.

Anyone have an idea as to why this is?

 ![Screenshot 2024-01-29 at 4.05.33 PM](https://us1.discourse-cdn.com/getpostman/original/3X/c/8/c8eb4eb88c133369a608a58edf5eb848d38c4815.png)

 ![Screenshot 2024-01-29 at 4.06.28 PM](https://us1.discourse-cdn.com/getpostman/original/3X/9/0/90c7d8459cea126ab6e5ea9fffe0df65e4b4a9ec.png)

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [January 29, 2024, 9:31pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/2 "2024-01-29T21:31:28Z")

</div>

Hi @nategerman. Welcome to the Postman Community!

Can you share a screenshot of your request header tab?

---

<div class="post-metadata">

**Author:** ![nategerman](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nategerman](https://community.postman.com/u/nategerman)\
**Post date:** [January 29, 2024, 9:39pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/3 "2024-01-29T21:39:51Z")

</div>

Sure can.

 ![Screenshot 2024-01-29 at 4.38.00 PM](https://us1.discourse-cdn.com/getpostman/original/3X/8/b/8b38a493d4d311ba7fe82362eb670363e1e4fb12.png)

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 30, 2024, 1:52pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/4 "2024-01-30T13:52:58Z")

</div>

You appear to be using the authorization code grant type, which requires user interaction.

I don’t use the CLI, but I can’t see how this grant type would be possible.

---

<div class="post-metadata">

**Author:** ![nategerman](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nategerman](https://community.postman.com/u/nategerman)\
**Post date:** [January 30, 2024, 6:52pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/5 "2024-01-30T18:52:01Z")

</div>

That’s the point of the Authorization tab. Once it is set up, it is supposed to handle the authentification for the request.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 31, 2024, 12:45pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/6 "2024-01-31T12:45:30Z")

</div>

The authorization helpers can do a lot, but they can’t interact with the browser. All they do is open the browser for you to enter the appropriate details.

When you run this in the desktop\web app, doesn’t it pop up in the browser for you to enter your username and password before it then provides the authentication token?

In your screenshot, you have the call back URL and “authenticate via browser” selected.

Have a look at the following…

[Microsoft identity platform and OAuth 2.0 authorization code flow - Microsoft identity platform | Microsoft Learn](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow)

As far as I’m aware, the auth code grant type requires user interaction, so you will not be able to automate this in the CLI or in Newman.

Personally, I would change the grant type for something that can be automated, and then have a few manual tests for testing the auth code flow.

We use Microsoft for authentication on a few projects, and the premise is that we aren’t really testing the hosted Microsoft service, but the application we land on after we authenticate.

Therefore we have the grant type set on the non-production systems to also allow another grant type like “password” to enable us to automate the authentication and then have some manual tests in PRE-PROD and PROD to test the auth code flow.

If you are using OpenID on top of OAuth2, you can check to see what grant types are configured by looking at the well known configuration.

For example…

[https://login.microsoftonline.com/{{tenantId}}/v2.0/.well-known/openid-configuration](https://login.microsoftonline.com/%7B%7BtenantId%7D%7D/v2.0/.well-known/openid-configuration)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 1, 2024, 12:46pm UTC](https://community.postman.com/t/oauth-isnt-passing-to-the-request-in-cli/57057/7 "2024-03-01T12:46:06Z")

</div>

Closed on March 1, 2024, 12:46pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
