Reputation: 22956
I'm trying to bind a graphToken in a http azure function like so:
//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"
}
]
}
The function itself in 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);
}
When attempting to do a GET request on the function I get an exception:
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()
The function itself is secured using Azure AD B2C and when called the users id_token is passed in as a bearer authorization.
From my understanding there are some features not supported by B2C that is supported by Azure AD - is this one of them?
Upvotes: 0
Views: 2319
Reputation: 1358
What is almost certainly going on here is that no authentication has actually occurred, so there is no token for the application to grab. We should definitely have a better error message in this case.
There are two easy ways around this:
Upvotes: 2