Question

Set a computed field after a token refresh request

  • 22 June 2023
  • 0 replies
  • 26 views

Badge +1

I’m trying to capture the access_token part of this response and use it in subsequent actions:

{
"access_token": "eyJhbG[REDACTED]",
"expires_in": 1800,
"token_type": "Bearer",
"refresh_token": "abcedfghijklmnopqrstuvwxyz"
}

First, I created a computed field with a key of access_token.

Next, I configured the session auth’s Configure a Token Exchange Request step:

const options = {
url: `https://apis.paycor.com/sts/v1/common/token?subscription-key={{bundle.authData.subscription_key}}`,
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/json'
},
params: {
},
body: {
'grant_type': 'refresh_token',
'refresh_token': bundle.authData.refresh_token,
'client_id': bundle.authData.client_id,
'client_secret': bundle.authData.client_secret
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

bundle.authData.access_token = results.access_token

return {
'sessionKey': results.access_token
};
});

I figured that setting bundle.authData.access_token = results.access_token would work, but it doesn’t seem to.  Does returning the sessionKey cause a problem?

What am I missing?  Is there a way to use z.console.log in this type of integration?


0 replies

Be the first to reply!

Reply