# Customize oauth2 refresh token url

**URL:** <https://community.postman.com/t/customize-oauth2-refresh-token-url/43922>\
**Category:** Help Hub\
**Tags:** authentication, oauth2\
**Created:** [February 13, 2023, 5:39pm UTC](https://community.postman.com/t/customize-oauth2-refresh-token-url/43922 "2023-02-13T17:39:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuele](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@samuele](https://community.postman.com/u/samuele)\
**Post date:** [February 13, 2023, 5:39pm UTC](https://community.postman.com/t/customize-oauth2-refresh-token-url/43922/1 "2023-02-13T17:39:26Z")

</div>

The API I’m using has a non-standard endpoint for token refresh.

I see where I can specify the url for auth and token. I need to customize the url for token refresh. Postman is trying to access the same endpoint as for obtaining the token. The api uses and endpoint specific for refreshing tokens.

---

<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:** [February 14, 2023, 12:40pm UTC](https://community.postman.com/t/customize-oauth2-refresh-token-url/43922/2 "2023-02-14T12:40:29Z")

</div>

I suspect you will have to mimic this in a pre-request script using sendRequest.

Here is a basic example of authenticating to Microsoft, which it sounds like you will need to extend to cater for the different URL’s.

```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);
            }
        });
    }
});

```
