Refresh Token and Access Token
# 🤝help
t
Hii can anyone help me to find out the solution for updating refresh and access token by providing refresh token at very 1st. Like I have refresh token and now I want to get access token. I can make request to get access token but it will expire in 24 hours. and when i generate new access token from refresh token it will also generate corresponding refresh token so i will not able to change the refresh token. so please anybody help me provide me solution for access token and refresh token managing strategy. I have api url and other details like client id and client secret.
t
thank you, but can you please elaborate more on refresh token. Like at first i should have to provide refresh token. And after that when i run a function to getrefreshtoken it will again generate new refresh token and access token ? now how i will able to provide this new refresh token in body?
l
Please check the documentation of the API you are implementing as they could be different for each provider. In my case the client secret and the refresh token does not change, the access token expires every 24 hours. As you see in the code, I do a check to validate if the token is still active. If not, I call the refreshtoken function to get a new token. The new token replaces the variable that was holding the last token. The action is performed in the hook after incoming message, so when a new message is received it verifies the token before proceeding to execute the workflow in the bot. This way the bot will always have a valid token
t
actually in my documentation accesstoken expires in 24 hours refreshtoken remain same untill i generate new access token with this refresh token so can you tell me any approach which would help me
l
It is exactly the same as I mentioned above, the refreshtoken does not change and is used to get a new access token. You can marry my code as is to get your desired outcome
t
but at very first I need to give refresh token how i can do this? keeping it in some variable? if so then when i use that refresh token i will get new access token and new refresh token then how can i overwrite this new refresh token to earlier created variable?
l
Copy code
const url = 'https://accounts.zoho.in/oauth/v2/token'
  const refreshToken = ''
Yes, declare a variable and store the static refreshToken in it. Do this within the hook in the studio, declare the access token at bot level (refer image) and then the code to check if accessToken is valid, if not use refreshToken to get new accessToken https://cdn.discordapp.com/attachments/1248545326780907583/1248864455480184862/image.png?ex=66653728&is=6663e5a8&hm=9ef75271655938a3652d1b0575d1c3f3958f11b2f72514d000c979360e58a74f&
you do not overwrite the refresh token, you overwrite the accesstoken
please read the code shared to help understand the logic
t
Thank you very much I am trying this script
l
I am sure it will work, hope you have tested the API using postman
29 Views