Its about the authlevel of the function.
If you use the authlevel = anonymous in you function.json file. Then you don't have to pass any access key and you can access the azure function api like the normal api endpoints.
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
For example you http trigger is http://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME> you can easily access this without any access/auth key.
If your are using the authlevel = function then you have to pass the access key/Api key with the http trigger endpoint while hitting it. If you don't you will get the 401 unauthorized.
{
"disabled": false,
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
You need to pass the key like as below example.
**https://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>?code=<API_KEY>
**
For the authlevel = function you can access the http trigger by the function key
and the host key. You will find the Get Function Url section when you open the function in the azure portal.
Note
With the host key you can access all of your http trigger endpoints its going to be common for all the http trigger. But the function key is unique for every function.
The third option is to use the authlevel = admin.
{
"disabled": false,
"bindings": [
{
"authLevel": "admin",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
For auth level admin the http trigger can only be access by the master key.
**https://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>?code=<MASTER_KEY>
**
You will find all these keys as per the auth levels in the Get Function Url section.
The complete guide for the authlevel is in this link.
Azure Functions HTTP trigger function authlevel Explanation
I hope this will be helpfull.
2.0.11888
released. After this runtime upgrade, got 401. New created function works fine. – Jerry Liu