Getting OAuth 2.0 refresh token to use in subsequent HTTP requests

I have a Microsoft Azure runbook which I am triggering using a webhook URL.

Using n8n’s HTTP Request node, I am able to make a POST request to the webhook, after which I receive a jobID in response.

I am supposed to be able to be able to GET the output of the previous request via the following URL

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobID}/output?api-version=2019-06-01
but a subsequent HTTP Request node fails due to either “Authorization failed - please check your credentials” or “Authentication failed. The ‘Authorization’ header is missing.” when I use either Microsoft OAuth 2.0 or Microsoft Entra ID credentials for the request.

This indicates that the refresh token is invalid, even though the OAuth 2.0 credentials were used previously to invoke the first HTTP Request.

How can I capture the refresh token and add it as a “Authorization : Bearer ____________” token in the header?
Or if I am otherwise going about this all wrong, how can I achieve what I need to do? (A similar flow I’ve built works in Okta Workflows, but not n8n).

My workflow is as follows:

  • n8n version: 1.5.1
  • Running via: Docker Compose
  • Operating system: Ubuntu Server

Hi @ThomasLu_EarthDaily, I am sorry you’re having trouble. I am not familiar with this API specifically, but n8n would attach the Authorization header just fine. You can verify this (for example) by replacing the URL temporarily with a URL provided by a service like webhook.site, which would allow you to inspect all requests it receives:

So I suspect the request might not be quite what it should be. Do you have this request working outside of n8n in curl/Insomnia/Postman? If so, perhaps you can import the working request using the Import cURL button on your second HTTP Request node?

image

Also, the workflow you have shared would essentially cause each of your HTTP Requests to be made twice, because the “POST Invoke Runbook” node has two input branches. This typically isn’t desirable so perhaps you want to remove the second connector, meaning your branch would run only once?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.