0

I want to call an azure function. The authentication for this function is enabled by Azure AD.

I want to call this function from an azure web job or internal tool that may use HTTP and connect the function automatically. In this case, there is no way to prompt a login page and then login.

Can I get a token for the function where AAD is enabled, and then while calling the function will send the token as bearer token?

How to accomplish that or any better idea?

Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48
  • Could you please tell me how you enable Azure AD auth. If you use [App Service Authentication](https://learn.microsoft.com/en-us/azure/app-service/overview-authentication-authorization), please refer to https://stackoverflow.com/questions/53499971/azure-function-authentication-using-azure-active-directory/53511688#53511688 – Jim Xu Apr 27 '20 at 05:00
  • Hope this link helps :- https://stackoverflow.com/a/60477376/4111181 – Anish K Apr 27 '20 at 13:37

1 Answers1

1

Regarding how to call the Azure function projected by Azure AD, please refer to the following steps

  1. Configure Azure AD for Azure Function enter image description here

  2. Get the details of AD application used to project Azure function

    a. Get application ID enter image description here

    b. Create client secret enter image description here

    c. Get Application Id Url enter image description here

  3. Use client credentials flow to get Azure AD access token

POST /<your tenant id>/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

grant_type =client_credentials
&client_id=<your application id>
&client_secret=<your client secret>
&resource=<your application id url>
  1. Call Azure function
<function url>

Authorization: Bearer <access token>

enter image description here

Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • Thanks, Jim. Though I can able to solve it finally it is always great to have a documentation for future reference. Thanks again! – Noor A Shuvo Apr 29 '20 at 05:20