Connection not refreshing access token

Hi,
I am trying to connect to a REST API that requires to get an access token from specific endpoint via user/password, OAuth is not supported. The token is JWT and has a lifetime of 30 Minutes.

My connetion is defined as:

{
	"url": "https://xxxxxxxx/api/v2/token",
	"method": "POST",
	"qs": {},
	"body": {
		  "userName" : "{{parameters.userName}}",
		  "password" : "{{parameters.password}}"
	},
    "response": {
        "data": {
            "accessToken": "{{body}}",
			"expires": "{{addSeconds(now, 1200)}}"
        }
    }
}

I was expecting, that a new token is aquired when the old one expires. But this is not happening…

Is my definition wrong?

Best Regards
Jörg

Greetings Jörg,

You’ll have to build out the refresh process. Based on the connection information that you’ve added, there isn’t anything doing that currently. If you can post the REST API docs I might be able to help point you in the right direction. A lot of “JWT” connections really need to use some of the connection details from the OAuth2 connection example: OAuth2 - Make Apps

Here’s the connection from the QuickBooks app to give you an idea. Note the refresh portion. :

{
    "authorize": {
        "qs": {
            "scope": "{{join(oauth.scope, ',')}}",
            "client_id": "{{ifempty(parameters.clientId, common.clientId)}}",
            "redirect_uri": "{{oauth.redirectUri}}",
            "response_type": "code"
        },
        "url": "https://appcenter.intuit.com/connect/oauth2",
        "response": {
            "temp": {
                "code": "{{query.code}}"
            },
            "data": {
                "realmId": "{{query.realmId}}"
            }
        }
    },
    "token": {
        "url": "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer",
        "method": "POST",
        "body": {
            "code": "{{temp.code}}",
            "client_id": "{{ifempty(data.clientId, common.clientId)}}",
            "grant_type": "authorization_code",
            "redirect_uri": "{{oauth.redirectUri}}",
            "client_secret": "{{ifempty(data.clientSecret, common.clientSecret)}}"
        },
        "type": "urlencoded",
        "response": {
            "data": {
                "expires": "{{addSeconds(now, body.expires_in)}}",
                "accessToken": "{{body.access_token}}",
                "refreshToken": "{{body.refresh_token}}"
            },
            "expires": "{{addSeconds(now, body.x_refresh_token_expires_in)}}"
        },
        "log": {
            "sanitize": [
                "request.body.code",
                "request.body.client_secret",
                "response.body.access_token",
                "response.body.refresh_token"
            ]
        }
    },
    "refresh": {
        "condition": "{{data.expires < addMinutes(now, 1)}}",
        "url": "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer",
        "method": "POST",
        "body": {
            "client_id": "{{ifempty(parameters.clientId, common.clientId)}}",
            "grant_type": "refresh_token",
            "client_secret": "{{ifempty(parameters.clientSecret, common.clientSecret)}}",
            "refresh_token": "{{data.refreshToken}}"
        },
        "type": "urlencoded",
        "response": {
            "data": {
                "expires": "{{addSeconds(now, body.expires_in)}}",
                "accessToken": "{{body.access_token}}",
                "refreshToken": "{{body.refresh_token}}"
            },
            "expires": "{{addSeconds(now, body.x_refresh_token_expires_in)}}"
        },
        "log": {
            "sanitize": [
                "request.body.client_secret",
                "request.body.refresh_token",
                "response.body.access_token",
                "response.body.refresh_token"
            ]
        }
    },
    "info": {
        "url": "https://{{if(data.useSandbox, 'sandbox-quickbooks', 'quickbooks')}}.api.intuit.com/v3/company/{{connection.realmId}}/companyinfo/{{connection.realmId}}",
        "headers": {
            "authorization": "Bearer {{connection.accessToken}}",
            "accept": "application/json"
        },
        "response": {
            "uid": "{{connection.realmId}}",
            "metadata": {
                "type": "text",
                "value": "{{body.CompanyInfo.CompanyName}} ({{body.CompanyInfo.Country}})"
            },
            "data": {
                "country": "{{body.CompanyInfo.Country}}"
            }
        },
        "log": {
            "sanitize": [
                "request.headers.authorization"
            ]
        }
    },
    "invalidate": {
        "url": "https://{{if(data.useSandbox, 'sandbox-quickbooks', 'quickbooks')}}.api.intuit.com/v2/oauth2/tokens/revoke",
        "headers": {
            "authorization": "Bearer {{connection.accessToken}}"
        },
        "log": {
            "sanitize": [
                "request.headers.authorization"
            ]
        }
    }
}```
2 Likes

Hi Luke,
i did not know, that OAuth is the right way to go here. It works :slight_smile:
Thank you!
Jörg

1 Like