Azure Active Directory 身份验证功能应用程序 [英] Azure active directory authentication Function App
问题描述
我正在通过以下 URL 为函数应用程序执行 azure Active Directory 身份验证
感谢任何帮助
如果您的 azure 函数身份验证级别是匿名的或还需要函数密钥,我们可以使用访问令牌直接访问您的 Azure 函数 API.详细步骤如下.
- 为 Azure Function 配置 Azure AD.请参考
然后我可以直接使用访问令牌.我用 Postman 测试过:
请注意,如果你的天蓝色函数认证级别不是匿名的,你需要添加函数密钥
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
解决方案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.
- 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.
- 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
这篇关于Azure Active Directory 身份验证功能应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!