In this Azure tutorial, we will discuss how to fix Authority’ Uri should have at least one segment in the path Error. I got this error while executing the Azure function Code to implement the Azure AD authentication to 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 the functionality to implement the Azure AD Authentication for the Azure Function for securing the Azure Function.
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 the below error
‘Authority’ Uri should have at least one segment in the path
The complete error message was as below
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 the reference

Why this Error?
This error I got because of Somewhat 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 got the same error in the Azure Portal because, as we all know, local.settings.json file changes will work for Our Local machine only. We will not get the reference of the local.settings.json file in Azure. So what I did was manually add all these Application settings key-value pairs for the Azure Function App.
‘Authority’ Uri should have at least one segment in the path Error [Solved]
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 settings with the name and value as shown below, and don’t forget to click on the Save Button finally.

These changes will fix the ‘Authority’ Uri should have at least one segment in the path Error in the Azure Portal after you publish the Azure Function into the Azure Portal.
You may also like following the articles below
Wrapping Up
In this Article, We discussed How to fix the Authority’ Uri should have at least one segment in the path Error I got while trying to execute the Azure function Code to implement the Azure AD authentication to secure the  Azure function using the Visual Studio 2019.
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