Hi all,
I have a rest API, The access token will expire in one hour. How can i do ... Please provide some reference examples. Thank you !!
To handle an expiring access token in OutSystems, you can implement a mechanism to refresh the token before it expires.
Store the Access Token and Expiry Time:
Create a Token Refresh Logic:
Integrate the Token Refresh Logic with API Calls:
Implementation :
Step 1: Store the Access Token and Expiry Time
Step 2: Create a Token Refresh Logic
Step 3: Integrate the Token Refresh Logic with API Calls
1. Store the Access Token and Expiry Time in entity (Token)
2. Create a Server Action to Refresh the Token (RefreshAcessToken)
3. check if the token is expired and call RefreshAccessToken (CheckAndRefreshToken)
But its still not running... I share my oml. Can you help me find it ... Thank you !!
Hi @NIZHEN LIN,
I believe the OML is fine and just need a condition to be updated in the server action.
You have written a condition that checks
CurrDateTime() < GetTokens.List.Current.Token.TokenExpiryAt which should be the other way around.
As per the condition written the flow will move to false all the time and only if the current time is lesser than the expiry you are refreshing the token.
eg: lets assume the current date and time is 6/4/2024 3:49:06 PM and the token expiry is 6/4/2024 2:49:06 PM
As per the existing condition 6/4/2024 3:49:06 PM < 6/4/2024 2:49:06 PM which is false and token will not be refreshed.
You can either swap the if condition connectors or update the condition as CurrDateTime() > GetTokens.List.Current.Token.TokenExpiryAt
Please update the if condition on the refresh server action and it should work fine.
Thanks,VP.
Thank you!! Refresh Token working :)
I still have a error ... My Access Token use on "Authorization" not running...
Can you help me find it Thank you !!
I didn't understand what you were exactly asking for
If it is about exposing API: you need to save the token generated time along with the token and need to check by logically whether it is used within an hour or not.
Consuming API: You need to find the refresh token API from the respected documentation site, and you can call that to avoid the expiration.
I use Consuming Api and refresh token. But Its still not running... I share my oml. Can you help me find it... Thank you !!
You can refer the below links,
[Microsoft Login Connector Core] OAuth2 token expiration interpreted with wrong timezone | OutSystems
Consume API with token and server action with cache | OutSystems
I refer the below links and it still not running ... what can I do ... Thank you !!