Azure active directory authentication Function App

橙三吉。 提交于 2020-01-25 10:21:07

问题


I am doing azure active directory authentication for function app by following below URL https://www.c-sharpcorner.com/article/secure-azure-function-with-azure-ad/

But when i hitting my url through function app It is giving unauthorized do i need to do anything else

please find the below screen shots.

any help is appreciated


回答1:


We could use the access token to access your Azure function API directly if your azure function authentication level is anonymous or function key is also required. The detailed steps are as below.

  1. Configure Azure AD for Azure Function. Please refer to https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings#auth.
  2. Get Access token

I get an access token from AAD using clientID and clientSecret using the following code:

METHOD: POST

Url : https://login.microsoftonline.com/your directory ID/oauth2/token 

HEADERS:  Content-Type : application/x-www-form-urlencoded

BODY: grant_type+=client_credentials&resource+=”your Function url”&client_id+++++=”the application that your register  id”&client_secret+=”the key you create”

Please note that according to the Azure Resources portal (https://resources.azure.com/), the default allowedAudiences is

https://{functionAppName}.azurewebsites.net/.auth/login/aad/callback

So I added the https://{functionAppName}.azurewebsites.net/ as allowed audiences.

Then I can use the access token directly. I tested it with Postman:

Please note that if your azure function authentication level is not anonymous, you need to add the function key



来源:https://stackoverflow.com/questions/55022474/azure-active-directory-authentication-function-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!