I have a function in a folder called 'TestMe', like so:
I can build the project in VSCode and upload it fine however the contents of function.json seems to be ignored.
My function is pretty simple:
[FunctionName("TestMe")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, string graphToken, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
and the function.json:
{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"type": "token",
"direction": "in",
"name": "graphToken",
"resource": "https://graph.microsoft.com",
"identity": "userFromRequest"
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
],
"disabled": false
}
I was following the guide here where I thought I could get a graphToken but instead all I got was this error:
Microsoft.Azure.WebJobs.JobHost.Validate(IFunctionDefinition function, object key) in JobHost.cs Microsoft.Azure.WebJobs.JobHost+d__36.MoveNext() in JobHost.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.Azure.WebJobs.Script.ScriptHost+d__86.MoveNext() in ScriptHost.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.Azure.WebJobs.Script.WebHost.Middleware.FunctionInvocationMiddleware+d__4.MoveNext() in FunctionInvocationMiddleware.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.Azure.WebJobs.Script.WebHost.Middleware.FunctionInvocationMiddleware+d__3.MoveNext() in FunctionInvocationMiddleware.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()
So I tried disabling the function and building/uploading the azure functions again from VSCode but I could still access the function making me believe the function.json is being ignored.