Seeking solution for automatic AWS Cognito token renewal in n8n

I’m trying to set up an n8n workflow that automatically refreshes my AWS Cognito OAuth tokens. Right now I have to manually update the token every day and it’s a pain. I made a workflow that’s supposed to hit the Cognito token endpoint but it’s not working like I thought it would. The token isn’t updating on its own. I still have to run the workflow myself to get a new access token. Does anyone know how to make this happen without me having to do anything? I really want to avoid having to remember to refresh it manually all the time. Any tips or tricks would be super helpful!

As someone who’s grappled with this issue, I can share what finally worked for me. I set up a dedicated workflow for token renewal, triggered by a Schedule node set to run about 15 minutes before the token’s expiry. The workflow uses an HTTP Request node to hit Cognito’s token endpoint, passing the refresh token stored in n8n’s credentials.

A crucial step was implementing error handling. I added a Switch node to check the HTTP response. If successful, it updates a ‘Token’ variable using the Set node. If it fails, it triggers a Slack notification so I’m aware of any issues.

To use the token across workflows, I created a sub-workflow that fetches the current token. Other workflows call this sub-workflow whenever they need the token, ensuring they always use the most recent one.

It took some trial and error, but this setup has been running smoothly for months now. No more manual refreshes!

hey mate, i’ve been there. try using the ‘schedul trigger’ node to auto-run daily before token expiry. ensure the refresh token is stored safely and passed correctly. if it’s still a hassle, hit me up.

I’ve encountered similar challenges with Cognito token renewal in n8n. Here’s what worked for me: Set up a Schedule Trigger node to run slightly before your token expiration time. Then, create an HTTP Request node to hit the Cognito token endpoint with your refresh token. Store the new access token securely, perhaps in n8n credentials or environment variables. Finally, use the Set node to update the token in your workflow variables. This approach should automate the process entirely, eliminating manual intervention. Just ensure your refresh token remains valid, as it has a longer lifespan but isn’t indefinite.