I have daployed an Azure function.
The function application is secured by Azure Active Directory, so in order to call it I have to log in using my AAD credentials.
And everything is fine when I make a GET call to that function.
But when I try to make a POST call, I'm receiving following error:
403 Forbidden
You do not have permission to view this directory or page.
The function is deployed using Visual Studio and its entry point looks like this:
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(
AuthorizationLevel.Anonymous,
"post", "get",
Route = null)] HttpRequestMessage req,
TraceWriter log)
{
...
}
Its working fine for me and below are the steps what I did:
[FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
name = data?.name;
}
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}