In this Azure tutorial, we will discuss how to fix the ‘Authority’ Uri should have at least one segment in the path Error. I encountered an error while executing the Azure function Code to implement Azure AD authentication and secure the Azure function using Visual Studio 2019.
Table of Contents
‘Authority’ Uri should have at least one segment in the path
I was working on implementing the Azure AD Authentication for the Azure Function to secure it.
Below is my Azure Function. I got the error on the line highlighted below.

public static HttpResponseMessage UpdateMessage(string body)
{
HttpResponseMessage newresponse;
AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/" + Environment.GetEnvironmentVariable("TenantID"));
ClientCredential clntCred = new ClientCredential(Environment.GetEnvironmentVariable("ClientID"), Environment.GetEnvironmentVariable("ClientSecret"));
AuthenticationResult authRes = authContext.AcquireTokenAsync(Environment.GetEnvironmentVariable("AudienceID"), clntCred).Result;When I ran the Project, I got this error
The complete error message was as follows
Executed ‘MyCallerFunction’ (Failed, Id=eb2d3d38-3c8d-4c3f-8dc6-18bd06b70ab4, Duration=705ms)
System.Private.CoreLib: Exception while executing function: MyCallerFunction. Microsoft.IdentityModel.Clients.ActiveDirectory: ‘authority’ Uri should have at least one segment in the path (i.e., https:////…)
Parameter name: authority.
You can see below for reference

Why this Error?
I got this error because I deleted the application settings Parameter values (TenantID, ClientID, ClientSecret, AudienceID, etc.) wrongly in my local.settings.json file. I overlooked that. Then, after seeing that, I have added them back with the Key-Value Pair. Now, I can fix this locally.
Now, I have published the Azure Function to the Azure Portal. After that, when I reran the Azure Function, I encountered the same error in the Azure Portal because, as we all know, changes to the local.settings.json file only take effect on our local machine.
We will not get the reference to the local.settings.json file in Azure. What I did was manually add all the application settings key-value pairs for the Azure Function App.
Solution
To fix this error locally in Visual Studio 2019, you need to add all the Application settings key-value pairs in your local.settings.json file along with the above Azure Function Code.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TenantID": "5d9d690a-####-474d-ae8b-#############",
"ClientID": "8dd5dd1a-cf07-4df3-bf02-522067679212",
"ClientSecret": "25Fbw-zf5T451Ke-QP5l7Pg1Tr_wG.UimW",
"AudienceID": "c63889d3-d0b5-4d7c-9060-b86e9e215da5",
"TargetURL": "https://secureapp.azurewebsites.net"
}
}To fix this error in the Azure Portal after you publish the Azure Function, you need to navigate to the Azure Function App —-> Click on the Configuration link from the left Navigation ——> Select the Application Settings tab —-> Click on the + New application setting button

Now, add each app setting with the name and value as shown below, and don’t forget to click on the Save Button finally.

These changes will resolve this error in the Azure Portal after you publish the Azure Function.
You may also enjoy the following articles.
I am Bijay, a Microsoft MVP (10 times) having more than 17 years of experience in the software industry. During my IT career, I got a chance to share my expertise in SharePoint and Microsoft Azure, like Azure VM, Azure Active Directory, Azure PowerShell, etc. I hope you will learn from these Azure tutorials. Read more
