Best answer

Connection label based on OAuth token data

  • 15 June 2020
  • 1 reply
  • 265 views

Hello!

I’m trying to implement an integration, and I’m stuck on the Connection label (meaning, it doesn’t show up necessary information).

 

I’d like to extract data from JWT token I receive from OAuth provider and use it as the Connection label, but I found no documentation on this subject. Is it actually possible?

 

I think, requesting user additional information, in order to put it into the label, is clumsy, especially when we have params in tokens.

Best regards,

Alexander Mustafin

icon

Best answer by ikbelkirasan 16 June 2020, 00:14

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 7
Badge +12

@sashker - Assuming the token is stored in authData.access_token and the connection label is set to {{username}} , try using the code snippet below in the authentication test function to parse the JWT token:

function parseJwt(token) {
const payload = Buffer.from(token.split(".")[1], "base64");
return JSON.parse(payload);
}

const userData = parseJwt(bundle.authData["access_token"]) // Assuming the token is stored in `access_token`. Calling this function would parse the token

return {
username: userData.username
}