# OAuth 2.0 Refresh Token - How To Use "In Body" Client Credentials

**URL:** <https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759>\
**Category:** Help Hub\
**Tags:** authentication\
**Created:** [January 10, 2023, 7:23pm UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759 "2023-01-10T19:23:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chasebarrett-ideiio](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@chasebarrett-ideiio](https://community.postman.com/u/chasebarrett-ideiio)\
**Post date:** [January 10, 2023, 7:23pm UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759/1 "2023-01-10T19:23:32Z")

</div>

_My question_:

Is it possible to coerce Postman’s built-in OAuth 2.0 “Refresh Token” function to use the same Client Authentication mode as the “Fetch Access Token” function? As best as I can tell, it always uses Basic Auth to fetch the refresh token.

_Details (like screenshots)_:

I’m using the built-in “OAuth 2.0” Authorization that Postman provides to fetch an access token. Because my OAuth AS is configured to support “form-based” (aka: “post”, or “in-body”) client authentication, I select “Send client credentials in body” as the “Client Authentication” mode and I’m able to fetch the access token just fine:

 ![Screenshot 2023-01-10 at 11.58.04](https://us1.discourse-cdn.com/getpostman/original/3X/a/f/afe9bc4b5eec6f1fbbb1f3875db1ea1fae083397.png)

Here’s the “fetch access token” request after clicking “Get New Access Token” that appears in the Postman console:

```auto
POST https://my.oauth.server.com/as/token 200 199 ms
  Request Headers
    Content-Type: application/x-www-form-urlencoded
    User-Agent: PostmanRuntime/7.30.0
    Accept: */*
    Cache-Control: no-cache
    Host: my.oauth.server.com
    Accept-Encoding: gzip, deflate, br
    Connection: keep-alive
    Content-Length: 280
  Request Body
    grant_type: "authorization_code"
    code: "some-auth-code"
    redirect_uri: "http://localhost/login/redirect-target"
    client_id: "my-client-id"
    client_secret: "my-client-secret"

```

So far, so good.

However, when it’s time to refresh the token, either automatically after the access token expires or explicitly when I click the “Refresh” link underneath my selected access token, I’m getting a 401 status code response with an error message that states “unsupported authentication method.”

Here’s the “refresh token” request that appears in the Postman console:

```auto
POST https://my.oauth.server.com/as/token 401 115 ms
  Request Headers
    Content-Type: application/x-www-form-urlencoded
    Authorization: Basic GsP...16=
    User-Agent: PostmanRuntime/7.30.0
    Accept: */*
    Cache-Control: no-cache
    Host: my.oauth.server.com
    Accept-Encoding: gzip, deflate, br
    Connection: keep-alive
    Content-Length: 712
  Request Body
    grant_type: "refresh_token"
    refresh_token: "eyJ...egQ"
  Response Body
    {
      "error" : "invalid_client",
      "error_description" : "Request denied: Unsupported authentication method"
    }

```

_I’ve already tried_:

If I choose “Send as Basic Auth header” when fetching the access token, I get an identical 401 response as shown above. This leads me to believe that if the refresh token request used the same “Client Authentication” mode as the fetch access token request, everything would work as expected.

I’ve also tried looking in the documentation, community forums, and the app’s settings to see if there’s an option for coercing this behavior, but I’m not finding anything.

---

<div class="post-metadata">

**Author:** ![sagars.esds](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@sagars.esds](https://community.postman.com/u/sagars.esds)\
**Post date:** [January 12, 2023, 6:56am UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759/2 "2023-01-12T06:56:09Z")

</div>

Really Appreciate it if anyone could explain how to use Client Authentication: send client credentials in the post body for refresh token call of oauth2 authentication of the postman

---

<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 12, 2023, 9:56am UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759/3 "2023-01-12T09:56:55Z")

</div>

@sagars.esds

Another option is to use a pre-request script instead of the built in authentication.

This is an example of authenticating to Microsoft.

It uses the expiry date and only gets a new token if it thinks the current one has expired.

```auto
pm.test("Check for collectionVariables", function () {
    let vars = ['clientId', 'clientSecret', 'tenantId', 'username', 'password', 'scope'];
    vars.forEach(function (item, index, array) {
        console.log(item, index);
        pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.undefined;
        pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.empty; 
    });

    if (!pm.collectionVariables.get("bearerToken") || Date.now() > new Date(pm.collectionVariables.get("bearerTokenExpiresOn") * 1000)) {
        pm.sendRequest({
            url: 'https://login.microsoftonline.com/' + pm.collectionVariables.get("tenantId") + '/oauth2/v2.0/token',
            method: 'POST',
            header: 'Content-Type: application/x-www-form-urlencoded',
            body: {
                mode: 'urlencoded',
                urlencoded: [
                    { key: "client_id", value: pm.collectionVariables.get("clientId"), disabled: false },
                    { key: "scope", value: pm.collectionVariables.get("scope"), disabled: false },
                    { key: "username", value: pm.collectionVariables.get("username"), disabled: false },
                    { key: "password", value: pm.collectionVariables.get("password"), disabled: false },                    
                    { key: "client_secret", value: pm.collectionVariables.get("clientSecret"), disabled: false },
                    { key: "grant_type", value: "password", disabled: false },
                ]
            }
        }, function (err, res) {
            if (err) {
                console.log(err);
            } else {
                pm.test("Status code is 200", () => {
                    pm.expect(res).to.have.status(200);
                });
                let resJson = res.json();
                pm.collectionVariables.set("bearerTokenExpiresOn", resJson.expires_in);
                pm.collectionVariables.set("bearerToken", resJson.id_token);
            }
        });
    }
});

```

---

<div class="post-metadata">

**Author:** ![kevj23](https://avatars.discourse-cdn.com/v4/letter/k/c4cdca/32.png) [@kevj23](https://community.postman.com/u/kevj23)\
**Post date:** [March 13, 2023, 1:50pm UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759/4 "2023-03-13T13:50:32Z")

</div>

I’ve just run into this same issue; I need the client\_id sent in the refresh request body, and it’s not clear where this can be turned on (if at all).

---

<div class="post-metadata">

**Author:** ![navigation-candidat4](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@navigation-candidat4](https://community.postman.com/u/navigation-candidat4)\
**Post date:** [October 18, 2023, 10:39pm UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759/5 "2023-10-18T22:39:39Z")

</div>

Hi, I’m fairly new to Postman and was having this issue. I solved it by setting this under Advanced parameters

![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/4/d490655e5210f35378dc89084c5de216bbc8284f.png)

In my case I have set the _clientId_ variable for the collection I’m working with.

---

<div class="post-metadata">

**Author:** ![navigation-candidat4](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@navigation-candidat4](https://community.postman.com/u/navigation-candidat4)\
**Post date:** [October 18, 2023, 10:48pm UTC](https://community.postman.com/t/oauth-2-0-refresh-token-how-to-use-in-body-client-credentials/42759/6 "2023-10-18T22:48:35Z")

</div>

Which I admit is weird and may be a bug because the documentation for the API I’m using doesn’t say I need to explicitly pass the client\_id parameter for the token refresh. I just decided to try this and it worked.
