web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / OAuth 2 how to re-auth...
Power Automate
Unanswered

OAuth 2 how to re-authenticate/refresh an expired token

(1) ShareShare
ReportReport
Posted on by 124

Hi all,

 

So I've managed to setup a O-Auth2 Power Automate function that will automatically use credentials to retrieve and return a access token. This Flow can be called by other Flows so long as they pass the credentials to it.

 

image.png

 

Now this works perfectly and the access token can be used to make API requests to the designated endpoint. The question is that the token only lasts 20 minutes and the returned access token also contains a line that indicates in seconds when it will expire. Is there a way to use this to setup a auto-refresh of the token if another Flow that's using this function takes longer than 20 minutes to call?

 

image.png

Categories:
I have the same question (0)
  • v-litu-msft Profile Picture
    Microsoft Employee on at

    Hi @Mick282,

     

    You could create a Do-Until action to put these actions into it, for we could control the recall times, we could initialize a integer variable before it, for example:Annotation 2019-11-27 151428.png

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MikeC282 Profile Picture
    124 on at

    Thanks @v-litu-msft .

     

    That's a good idea. How would this work from a perspective of updating the access token on a calling flow?

     

    My flow used to get the access token is just a function that a second Flow uses to get the access token to then perform a action. Below is the second flow that actually performs an API action once it has retrieved the access token.

     

    image.png

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello, @Mick282 ! Could you explain how you filled in the fields from each action, please?

  • Unkn0wn Profile Picture
    48 on at

    Hey @Mick282 , I'm also looking for the same. did you've figured out anything ?

  • franciscooa Profile Picture
    78 on at

    I was also looking for a good suggestion to implement something like this.

    Regards

  • MikeC282 Profile Picture
    124 on at

    Wow it's been a while since I created this post. @franciscooa 

    Are you looking for a solution to expiring tokens or overall? I've found a solution to the expiring token issue. Basically disregard the expiry time. Generate the the bearer access token and store it (I'm using the environment variable in the Dynamics dataverse). Subsequent API calls will attempt to use that token. I wrap this around a Scope step in Power Automate and and then add in a fail scope (i.e. if the attempt to use the current access token fails because it has expired) to generate and store a new access token if the try scope fails.

  • franciscooa Profile Picture
    78 on at

    Hi @Mick282 !

    Thanks for your answer. Meanwhile, I developed a flow that is checking a .txt file that has the "access_token" and the "expiration" fields. If the current time > expiration, I'll generate a new token and then update the txt file with the refreshed details. Maybe I can use the environment variables to store that, I guess.

    Thanks for your suggestion. 

    Regards

  • oburgos Profile Picture
    on at

    It would be possible for you to share an example?

  • FelixK Profile Picture
    36 on at

    I solved this in a different approach within one flow. 
    1. HTT P to get the token on the first time and

    2. Store it to a Variable "VARAuthToken"

    Now i build the flow until the first time I use it to call the API. right after thist call i add a condition. 
    3. Condition on the Response body of the previous  API call, In  my case the response on a invalid token looks like:

    "body": {
    "error": "invalid_token",
    "error_description": "'exp' claim expired at Wed, 31 May 2023 14:27:36 GMT"
    }

    So i check on this "Error" = "invalid token". If this condition is raised, then 

    4. run  another Get Token http and update the initial variable set in Step 2. 
    Note: The Condition = false path is left empty and the subseqence flow is then after the entire condition case.

    this Looks like: 

    FelixK_0-1685610171038.png

     



Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 86 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 55

#3
Ellis Karim Profile Picture

Ellis Karim 53 Super User 2026 Season 1

Last 30 days Overall leaderboard