我试图在http azure函数中绑定graphToken,如下所示:
// function.json:
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"type": "token",
"direction": "in",
"name": "graphToken",
"resource": "https://graph.microsoft.com",
"identity": "userFromRequest"
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
]
}
run.csx中的函数本身:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static IActionResult Run(HttpRequest req, string graphToken, TraceWriter log)
{
return (ActionResult)new OkObjectResult(graphToken);
}
当尝试对函数执行GET请求时,我得到一个异常:
An unhandled exception occurred while processing the request.
InvalidOperationException: Error while accessing 'X-MS-TOKEN-AAD-ID-TOKEN': property doesn't exist.
Microsoft.Azure.WebJobs.Host.Bindings.Path.BindingTemplateToken+ExpressionToken.Evaluate(IReadOnlyDictionary<string, object> bindingData) in BindingTemplateToken.cs, line 198
InvalidOperationException: Exception binding parameter 'graphToken'
Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw() in DelayedException.cs, line 27
FunctionInvocationException: Exception while executing function: Functions.HttpTriggerCSharp1
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
使用Azure AD B2C保护函数本身,并在调用时将用户id_token作为承载授权传入。
根据我的理解,Azure AD支持的某些功能不受B2C支持 - 这是其中之一吗?
答案 0 :(得分:2)
这里几乎可以肯定的是,实际上没有发生任何身份验证,因此应用程序无法获取令牌。在这种情况下,我们肯定会有更好的错误消息。
有两种简单的方法: