cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Knots
Frequent Visitor

Custom Connector - OAuth2 - Old refresh token used

We've created a custom connector for Exact Online, but are having issues with the access tokens. Everything works, but at some point the connection states it "Can't sign in" and you'll need to fix the connection before you can use it again. When checking the detail of that connection, it states:

 

 

 

Failed to refresh access token for service: oauth2. Correlation Id=..., UTC TimeStamp=..., Error: OAuth 2 access token refresh failed. Client ID and secret sent in form body.. Response status code=Unauthorized. Response body: {"error":"unauthorized_client","error_description":"Old refresh token used."}

 

 

 


The authentication type of the custom component is set to OAuth2. The identity provider is the Generic OAuth2 one. It uses the "Authorization Code" flow. We've tried the "Implicit" one as well to no avail.

 

Since the connection works initially, the authorization and token URL seem to be correct. We can authenticate and use the connection in an, e.g. Canvas App.
According to the documentation, the refresh URL is the same as the token URL:

 

 

 

../api/oauth2/token

 

 

 


If the token would expire once a month or so, I could live with it, but the token expires after just 10 minutes...

Can anyone tell me why an old refresh token is used? Is the token simply not updated after refreshing it? Is it refreshing multiple times simultaneously, in which case the second call probably results in the error?

What am I missing?

 

edit: added additional information regarding the authentication method.

50 REPLIES 50
HEATFreight
Kudo Kingpin
Kudo Kingpin

Here is a wayback machine link to the QBO API custom connector tutorial that I linked to above. This might take a while to load, but it has all the screenshot photos and instructions that I used. "Print to PDF" this archive page, and then you can easily reference it later.

Hi @HEATFreight,

 

Thanks for your reply. But the link seems to refer to your custom connection for QuickBooks. I was more interested in this part of your comment:

 

"The other 3rd-party API does not follow the OAuth2 spec. At this point I forget exactly what the issue was, but their implementation is incorrect. And they can't easily fix it because it's a widely used API in production with thousands, possibly millions, of users. We had to deploy it via Power Automate flows. We have Parent flows and Child flows, and the Child flows can't use any "run-only user" connections. In other words, all connectors in the Child flows must be in maker context.

Our PowerApps canvas app sends requests to Parent flows which then run the Child flows to perform API requests using the HTTP action in Power Automate. We even have backend flows triggered on SharePoint edits which run the Child flows to refresh tokens and make API requests on behalf of the user for automated backend tasks.
"

 

I would like to create something similar for the Exact Online API, but I don't know if I'm skilled enough. I hope you can give some more details in the form of screenshots or something, so it would be easier to recreate it for our environment. Did you manage to do it without code, only with flows? 

 

Hope you can give me a bit of a head start. Thnx!


 

You can do it with flows only, but I do not recommend.

Power Automate is atrocious. I have had it with their unprofessional service and downright abysmal support (I'm looking at you Tata Consultancy Services).

 

Slightly unrelated, but their GitHub integration within PowerApps is a joke. And the entire Power suite's ridiculously slow page loads when editing apps or flows has derailed my progress and killed my development pace time and time again. I am constantly plagued by bugs that further degrade the experience.

For instance, if you have several flows open for which you commonly need to edit the code or investigate run data, occasionally Power Automate will decide that your session is expired (presumably) and force some sort of reauthentication that fails with an "Out of storage" error (no matter whether you use Chrome or Edge, fully updated), thus causing you to lose the actual URL of that flow from your browser history within that tab (and all other focused Power Automate tabs within each browser window). And if the "Out of storage" error is still ongoing at the moment you view that browser tab, then upon navigating back to try to get back to the flow URL, your history in that tab disappears and you completely lose context to the flow which is supposed to live in that browser tab. Hope you bookmarked all your flow tabs in a folder or your screwed!

Microsoft: "Torturing users with attention deficits since 1975".

I am halfway through the process of pulling the plug on Power Automate completely. My Power Apps canvas app will call no flows when I'm done with this!

All flow logic moves to Azure Function Apps. Currently have at least three console apps running in production on Azure, although I had no idea how to write console apps before this. Basically, just converted each flow's functionality to pseudocode and asked ChatGPT to write a console app to implement that logic. It takes quite a bit of customization of the ChatGPT-written code and it's a lengthy iterative process to feed the current refactoring of the code back into ChatGPT to refactor it again until it meets your needs, but it's worth it to learn something new. Azure is great. Power Automate blows. Stay far away. Do not under any circumstances trust mission critical code to Power Automate. I mean it will probably kind a work and it's easy for simple stuff, but with ChatGPT now lowering the bar for entry-level console app development, there is simply no point in screwing around with Power Automate. I wish ChatGPT had come out three years ago and then I wouldn't be stuck with this Power Apps bull💩 too. Power Apps is only marginally more usable that Power Automate for professional, mission critical infrastructure. I fully intend to replace my entire canvas app with a Next.js webapp.

Low code was a mistake. Anybody got a time machine leaving for 2020? Planning to steal the gpt4 weights from OpenAI, as well as COVID vaccine efficacy data from Pfizer and Moderna, and travel back to February 1st, 2020. We can fix the last three years! Who's with me?

EDIT: Let me just say that the real impetus for switching away from Power Automate to Azure Function Apps was that there was little to no Power Automate training in OpenAI's models (gpt3 and gpt4). And Power Apps for that matter. ChatGPT just does not natively understand powerFx syntax (which itself is a disjointed amalgamation of syntaxes: you have the JSON data that describes a flow or canvas app in the context of, for instance, the same format used in the files within an exported Power Automate solution vs. the powerFx syntax within a canvas app vs. the powerFx syntax of the visual coding elements in a flow vs. the powerFx syntax of flow expressions).

If you try to copy the visual coding blocks (actions and other coding elements like data compose/select/filter, etc.) in a Power Automate flow, which includes any expressions embedded within, you get JSON data that looks totally different than what you see on the page, and it's quite hard to parse because it encodes all the connection data and whatnot. So, it's quite hard to just copy your logic for an iterative AI-based approach to refactoring. You can get ChatGPT to work with powerFx syntax (whether canvas app syntax or flow expression syntax or, presumably, the JSON syntax too). The problem with the full JSON syntax is you hit the limit of the context window rather quickly. But you can get ChatGPT to respect the syntax. You just have to specifically prompt it that the syntax is not: javascript, C#, C++, C, etc. Example prompt: "Do not change the syntax. Do not remove code unnecessarily. Do not make any unnecessary changes. Refactor the code to do abc123." It will handle basic stuff ok, and it would probably do pretty well if you boosted the prompt with documentation for all the Power Automate expression functions, but it does not know them last I tried. And even if it did "know" the powerFx syntax and available expressions, it would not be easy to copy over new code. You would essentially need to delete entire "scope" blocks and paste in the JSON of the refactored "scope" blocks from clipboard. It would be clumsy and slow. Not integrated with GitHub. Pretty much a joke. (Granted, they now have some kind of AI editor assistance for Power Automate, but totally useless for me because it only works for new flows, so Microsoft just says "🖕 you, have some technical debt!")

Anyway, by moving away from Power Automate to Azure Function Apps using other languages well-supported by ChatGPT training data I have massively increased the pace of my development. Power Automate will do nothing but slow you down and hinder your future progress. It was helpful to me three years ago because ChatGPT did not exist. Today I would say No Code / Low Code is dead.


Iteratively prompting ChatGPT to fix your code will quickly teach you how to code.

Thanks for your answer @HEATFreight. I'm with you for the most part, but I'm not really a developer. I can handle flows for most part, but programming is another level. Learning Azure Function Apps would take far more time. Time that I don't have at the moment. We are a small company with simple integration needs, so Flows were kind of ideal. But this simple integration with Exact Online is a pain, because of the strict policies of their API.

 

I will dig a little bit deeper in Azure Function Apps, but I will have to outsource it then, I think. That's not what I wanted.

 

Can you show me your setup with the flows, non the less? Then I can make a proper evaluation for our situation.

GrootCRM
Advocate II
Advocate II

I build a custom connector to Exact Online that I use in flows and only expires when it is inactive for a month. So, it seems possible :-). Let's identify the variances so we can document them here. Below, you'll find a screenshot of my Security tab:

 

GrootCRM_0-1696322887592.png

Please feel free to contact me directly if you have further questions.

 

Kind regards,

Elowy.

I use Custom Connectors or Azure Function Apps to make API requests.

I can't recommend flow because it requires the same complexity as building a context app (if you want it to work right). If you do not build out support for handling of exceptions and edge cases, what's the point?

My flows to handle API requests ended up being so complicated that I don't think you would benefit from me trying to show you how I did it. And they still fail to account for the variety of edge cases that my Azure Function Apps handle.

There's no catch-all solution. You just have to read the documentation for the API you're using and attempt to match the structure of your request to the examples in the documentation.

Don't use flow. Pay for ChatGPT and ask it for help. That's literally all I did.

Hi @GrootCRM,

 

My security tab is identical and my connection also works for about a month and then loses it's connection. Only that is not because of inactivity? Are you sure it is because of inactivity at your end? Not because of the reason mentioned in this thread?

 

Do you use only one endpoint of Exact Online? When I added a second endpoint for another integration, the connection failed every few hours. That is not workable in a production environment anymore. I have tried to create a second custom connector for the second endpoint, but that didn't make a difference. I will soon try to run the second connector with a different user to see if that works better, but a user for every endpoint is also not really a solution (pricey). 

 

As I understand it, reading through all the info, the policies that Exact Online enforces on it's API just doesn't work flawless with the custom connector.

GrootCRM
Advocate II
Advocate II

Hi @JOAS_Niels ,

 

Actually I'm not sure if the connection will remain after a month. I can tell you in a few days, when a month is expired since the last connection update 😉

I don't know what your definition of endpoint is, but we use several services from Exactonline, like  PurchaseInvoices, -lines, Contacts, Projects and more...

 

Cheers!

Elowy.

 

Hi @GrootCRM,

 

Yes, that's what I meant with endpoints. Do you use the same custom connector and user for each endpoint? When I added the second endpoint the failures became a lot more frequent.

 

I'm curious how your connector will function the coming weeks.

How did this work out, one year later?

I have not found a solution to the problem. The connector fails approximately once per month. That is, when you use the same connection for each flow. If you create multiple custom Exact connectors or use multiple connections with the same connector, then it fails within a couple of hours.

 

That's my experience.

 

The alternatives are developing a custom proxy yourself (I have not tried this yet, probably above my pay grade) or a paid service that has a connection to Exact.

Piebe_Post
Advocate I
Advocate I

Hi Joas, thanks for your reply.

 

Until a few weeks ago I had it failing approximately once a week or so. But now it fails about twice a day. Only got one connection, don't really know what happened.

 

This kind of s****. If I knew this beforehand, we'd probably pick another ERP, but it's too late to switch. I think I'll build an Azure Service as a proxy, which I'll authenticate with an implicit grant type.

I know what you mean, it's so frustrating!

 

Just in case, be sure to set the connection in your flow step to the same connection everywhere.

2024-05-27 09_30_25-Window.png

It should also be the same connection as your test connection if you have tested it in the edit view of the custom connector itself:

2024-05-27 09_34_48-Window.png

This was an eye opener for me. These connections also interfere with each other.

 

But it is still not production environment worthy when it fails once per month.

 

Love to see your solution if you go the custom proxy path!

Thanks for your extensive reply. I only got one connection present in my environment, so I can never use different ones around multiple flows.

 

I suspect that the refresh chain keeps breaking because the refresh request is made "too late" from time to time, so after 10:00 minutes (say 10:02 minutes, which is 2 seconds too late). So another thing I think about is building a flow that creates a key (maybe implicit), stores the key in an Azure Key Vault and repeats this process every 9:30 minutes. Then I could get the key for each flow and put it inside the header of the Exact actions present in that flow. Might be easier. But not sure if this makes sense, didn't really overthink this scenario yet.

GrootCRM
Advocate II
Advocate II

Same here. My customer has to refresh the connection each month. Unfortunately...

Each month, at set times (so known beforehand)? Or when it randomly fails?

 

It's not really a solution for me. I'll try some solutions in the coming weeks.


@Piebe_Post wrote:

Thanks for your extensive reply. I only got one connection present in my environment, so I can never use different ones around multiple flows.

 

I suspect that the refresh chain keeps breaking because the refresh request is made "too late" from time to time, so after 10:00 minutes (say 10:02 minutes, which is 2 seconds too late). So another thing I think about is building a flow that creates a key (maybe implicit), stores the key in an Azure Key Vault and repeats this process every 9:30 minutes. Then I could get the key for each flow and put it inside the header of the Exact actions present in that flow. Might be easier. But not sure if this makes sense, didn't really overthink this scenario yet.


Maybe a flow that does a dummy request every 8 minutes with the same connection would be a workaround for now?


@Piebe_Post wrote:

Each month, at set times (so known beforehand)? Or when it randomly fails?

 

It's not really a solution for me. I'll try some solutions in the coming weeks.


I don't think it's at set times.

Something like that. But just making a dummy request doesn't fit the bill I'd think, since the dummy request should be able to update the refresh token and the access token that is stored somewhere in the connection settings (or whatever that's called) of Power Platform.

 

So I'm thinking of a solution, probably an Azure Service since a flow cannot present a login screen, that creates and maintains a connection and stores the keys inside a key Vault. I'd update the custom connector to include a header field for the access token, which will be retrieved using the Azure Key Vault connector.

 

Or even better, I'd like to be able to manipulate the custom connector in a way that it doesn't refresh after 10 minutes but after 9:30 minutes instead. But as far as I know, there isn't such a possiblity, but haven't looked into that yet.

I don't believe the last thing is possible. 

 

If I'm not mistaken, with a dummy flow, the token will stay valid and you would not need to refresh it. Or am I missing something? At least for a month or so....

Helpful resources

Announcements

Update! June 13th, Community Ambassador Call for User Group Leaders and Super Users

Calling all Super Users & User Group Leaders   UPDATE:  We just wrapped up June's Community Ambassador monthly calls for Super Users and User Group Leaders. We had a fantastic call with lots of engagement. We are excited to share some highlights with you!    Big THANK YOU to our special guest Thomas Verhasselt, from the Copilot Studio Product Team for sharing how to use Power Platform Templates to achieve next generation growth.     A few key takeaways: Copilot Studio Cookbook Challenge:  Week 1 results are posted, Keep up the great work!Summer of Solutions:  Starting on Monday, June 17th. Just by providing solutions in the community, you can be entered to win tickets to Power Platform Community Conference.Super User Season 2: Coming SoonAll communities moving to the new platform end of July We also honored two different community members during the call, Mohamed Amine Mahmoudi and Markus Franz! We are thankful for both leaders' contributions and engagement with their respective communities. 🎉   Be sure to mark your calendars and register for the meeting on July 11th and stay up to date on all of the changes that are coming. Check out the Super User Forum boards for details.   We're excited to connect with you and continue building a stronger community together.   See you at the call!

Copilot Cookbook Challenge | Week 2 Results | Win Tickets to the Power Platform Conference

We are excited to announce the "The Copilot Cookbook Community Challenge is a great way to showcase your creativity and connect with others. Plus, you could win tickets to the Power Platform Community Conference in Las Vegas in September 2024 as an amazing bonus.   Two ways to enter: 1. Copilot Studio Cookbook Gallery:  https://aka.ms/CS_Copilot_Cookbook_Challenge 2. Power Apps Copilot Cookbook Gallery: https://aka.ms/PA_Copilot_Cookbook_Challenge   There will be 5 chances to qualify for the final drawing: Early Bird Entries: March 1 - June 2Week 1: June 3 - June 9Week 2: June 10 - June 16Week 3: June 17 - June 23Week 4: June 24 - June 30     At the end of each week, we will draw 5 random names from every user who has posted a qualifying Copilot Studio template, sample or demo in the Copilot Studio Cookbook or a qualifying Power Apps Copilot sample or demo in the Power Apps Copilot Cookbook. Users who are not drawn in a given week will be added to the pool for the next week. Users can qualify more than once, but no more than once per week. Four winners will be drawn at random from the total qualifying entrants. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once. If they are drawn multiple times, another user will be drawn at random. Prizes:  One Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value, does not include travel, lodging, or any other expenses) Winners are also eligible to do a 10-minute presentation of their demo or solution in a community solutions showcase at the event. To qualify for the drawing, templates, samples or demos must be related to Copilot Studio or a Copilot feature of Power Apps, Power Automate, or Power Pages, and must demonstrate or solve a complete unique and useful business or technical problem. Power Automate and Power Pagers posts should be added to the Power Apps Cookbook. Final determination of qualifying entries is at the sole discretion of Microsoft. Weekly updates and the Final random winners will be posted in the News & Announcements section in the communities on July 29th, 2024. Did you submit entries early?  Early Bird Entries March 1 - June 2:  If you posted something in the "early bird" time frame complete this form: https://aka.ms/Copilot_Challenge_EarlyBirds if you would like to be entered in the challenge.   Week 1 Results:  Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1.  @Mathieu_Paris 1.   @SpongYe 2.  @Dhanush 2.   @Deenuji 3.  n/a3.   @Nived_Nambiar  4.  n/a4.   @ManishSolanki 5.  n/a5.    n/a   Week 2 Results:  Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1. Kasun_Pathirana1. ManishSolanki2. cloudatica2. madlad3. n/a3. SpongYe4. n/a4. n/a5. n/a5. n/a

Win free tickets to the Power Platform Conference | Summer of Solutions

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**

Celebrating the June Super User of the Month: Markus Franz

Markus Franz is a phenomenal contributor to the Power Apps Community. Super Users like Markus inspire others through their example, encouragement, and active participation.    The Why: "I do this to help others achieve what they are trying to do. As a total beginner back then without IT background I know how overwhelming things can be, so I decided to jump in and help others. I also do this to keep progressing and learning myself." Thank you, Markus Franz, for your outstanding work! Keep inspiring others and making a difference in the community! 🎉  Keep up the fantastic work! 👏👏 Markus Franz | LinkedIn  Power Apps: mmbr1606  

Your Moment to Shine: 2024 PPCC’s Got Power Awards Show

For the third year, we invite you, our talented community members, to participate in the grand 2024 Power Platform Community Conference's Got Power Awards. This event is your opportunity to showcase solutions that make a significant business impact, highlight extensive use of Power Platform products, demonstrate good governance, or tell an inspirational story. Share your success stories, inspire your peers, and show off some hidden talents.  This is your time to shine and bring your creations into the spotlight!  Make your mark, inspire others and leave a lasting impression. Sign up today for a chance to showcase your solution and win the coveted 2024 PPCC’s Got Power Award. This year we have three categories for you to participate in: Technical Solution Demo, Storytelling, and Hidden Talent.      The Technical solution demo category showcases your applications, automated workflows, copilot agentic experiences, web pages, AI capabilities, dashboards, and/or more. We want to see your most impactful Power Platform solutions!  The Storytelling category is where you can share your inspiring story, and the Hidden Talent category is where your talents (such as singing, dancing, jump roping, etc.) can shine! Submission Details:  Fill out the submission form https://aka.ms/PPCCGotPowerSignup by July 12th with details and a 2–5-minute video showcasing your Solution impact. (Please let us know you're coming to PPCC, too!)After review by a panel of Microsoft judges, the top storytellers will be invited to present a virtual demo presentation to the judges during early August. You’ll be notified soon after if you have been selected as a finalist to share your story live at PPCC’s Got Power!  The live show will feature the solution demos and storytelling talents of the top contestants, winner announcements, and the opportunity to network with your community.  It's not just a showcase for technical talent and storytelling showmanship, show it's a golden opportunity to make connections and celebrate our Community together! Let's make this a memorable event! See you there!   Mark your calendars! Date and Time: Thursday, Sept 19th Location: PPCC24 at the MGM Grand, Las Vegas, NV 

Tuesday Tip | Accepting Solutions

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   To enhance our collaborative environment, it's important to acknowledge when your question has been answered satisfactorily. Here's a quick guide on how to accept a solution to your questions: Find the Helpful Reply: Navigate to the reply that has effectively answered your question.Accept as Solution: Look for the "Accept as Solution" button or link, usually located at the bottom of the reply.Confirm Your Selection: Clicking this button may prompt you for confirmation. Go ahead and confirm that this is indeed the solution.Acknowledgment: Once accepted, the reply will be highlighted, and the original post will be marked as "Solved". This helps other community members find the same solution quickly. By marking a reply as an accepted solution, you not only thank the person who helped you but also make it easier for others with similar questions to find answers. Let's continue to support each other by recognizing helpful contributions. 

Top Solution Authors
Users online (2,064)