logicapps icon indicating copy to clipboard operation
logicapps copied to clipboard

Refresh token for managed API connections in VS Code

Open h-t-w opened this issue 3 years ago • 4 comments

Hi.

I am developing a LogicApp locally in VS Code and I have a hard time figuring out how to refresh the tokens of managed API connections.

When I am creating a new connection the relevant information is saved in the connections.json and in local.settings.json. Additionally, I get an info in VS Code that the connection is only valid for n days - as is also stated in the official documentation. Unsurprisingly, I get an error if I try to run the LogicApp after these n days are passed (Error: 'Lifetime validation failed. The token is expired'). So far as expected.

What I am unable to figure out is how I am supposed to refresh the tokens manually/programmatically after they expired. Below excerpts from the json files.

connection.json

"azurevm": {
      "api": {
        "id": "/subscriptions/XXXXX/providers/Microsoft.Web/locations/northeurope/managedApis/azurevm"
      },
      "connection": {
        "id": "/subscriptions/XXXXX/resourceGroups/XXXXX/providers/Microsoft.Web/connections/azurevm"
      },
      "connectionRuntimeUrl": "XXXXX",
      "authentication": {
        "type": "Raw",
        "scheme": "Key",
        "parameter": "@appsetting('AZUREVM_CONNECTION_KEY')"
      }

local.settings.json

"AZUREVM_CONNECTION_KEY": "eyJ0..........",

Any help would be greatly appreciated.

Best h-t-w

h-t-w avatar Feb 24 '22 15:02 h-t-w

Hi h-t-w

I was wondering if you'd had any luck in solving this problem? I'll got the same issue and can't find a solution anywhere :(

A

adrian-pritchard avatar Mar 14 '22 15:03 adrian-pritchard

@adrian-pritchard Sorry for getting back to you with such a delay.

I wasn't able to find a solution here. Two possible workarounds:

  • Depending on the number of connections (or dependencies) on quick fix is deleting the connection in Azure portal and setting up a new one, but doing this every 7 days will become annoying
  • What I am currently doing is not running the LA locally anymore. We have now a "development" LA and a "production" LA. Basic workflow is like this: Develop locally, commit changes, push to Azure DevOps, deployment of workflow to "development" LA is triggered, testing workflows, end finally if everything works out push to production.

h-t-w avatar Apr 08 '22 13:04 h-t-w

The first workaround doesn't seem to work in the current version (1.0.19). The token is not added to the local.settings.json when I recreate the connection and save the workflow. I had to revert to 1.0.14 where this does work.

sschutten avatar May 30 '22 06:05 sschutten

Any luck to solve this problem?

siddheshdp avatar Sep 30 '22 03:09 siddheshdp

I am pretty sure I have the same problem. I am developing locally and since I am using Azure Connectors, it made me pick a region, I picked region A. Created my Azure Connector which I see created in the resource group. Everything works fine.

Need to move to another region for development, changed the managedApiConnections API.id, connection.id, and connectionRuntimeUrl to match a connection created in the new region. Opened the designer and everything rendered fine.

When I try to use the workflow for locally, I get an error... "Error from token exchange: Invalid Authorization header. Authorization header is expected in the form 'Bearer token' or 'Key token'."

Can't find a way to refresh this. Any help would be appreciated.

karlrissland avatar Oct 19 '22 17:10 karlrissland