OAuth 2 Access token generation from Azure Function

Hi everyone,

I’m having a nightmare trying to use the OAuth 2 Access token generation in APIGee from an Azure Function.

So I have an Azure Function coded in C# using Rest sharp which is calling out API Proxy to get an Access token. We use this proxy in other applications and it works fine. We are using client_crendtial grant type. When I run the application locally I am able to get an access toekn with no issue in Postman or the browser, but when I publish it to the azure function, I get the following error:

{"Error":"Client credentials are required","ErrorCode":"invalid_client"}

I have found other Questions on this forum regarding this, and I think I have tried every combination of Parameters, headers etc in my request with no luck.

I’ve done:

  • set the header content-type to application/x-www-form-urlencoded

  • sent the client_id and secret in base64 and plain text with a : in the middle

  • sent the client_id on its own in the body

  • turned off all authorisation on the azure function incase that was the issue but I get the same error in the output whilst it works locally still.

  • sent Basic auth credtials alongside all of the options above

  • Created a new policy in APIGee with pass through

  • Removed the authorization header from the flow before the oauth policy

  • forced apigee to look in the policy for client_id in formparam using this:

    <ClientId>request.formparam.client_id</ClientId>
    

    I think thats everything I have tried.

Are there any specific issues that anyone is aware of when using an Azure Function to call APIGee like this? It’s such a simple function which works fine locally so I know that the code can talk to APIgee and get the repsonse I want.

Thanks

I’ve sorted it. I wasn’t setting my remote application setting variables correctly when publishing the application. That’s me feeling like a fool forever!

1 Like