'authority' Uri should have at least one segment in the path

{tocify} $title={Table of Contents}



Problem


Working on demo of calling AD secured function app from another function app. All testing went fine on my local machine however below error was thrown while testing after publishing it to portal.


authority Uri should have at least one segment in the path





Error



2020-01-08T09:52:10.451 [Error] Executed 'CallerFunctionHttpTrigger' (Failed, Id=e8d196b0-b107-447d-a8d8-07458c4873cb)
'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)

Parameter name: authority



Why it happened




In my code am referring to TenantID to form the authority URi ,which is to be fetched from AppSettings at runtime.

And below are the lines of code which is to get the access token from Azure AD and error was thrown against the first line (marked in yellow) 

AuthenticationContext authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/"+ Environment.GetEnvironmentVariable("TenantID"));

ClientCredential clientCredential = new ClientCredential(Environment.GetEnvironmentVariable("ClientID"),Environment.GetEnvironmentVariable("ClientSecret"));

AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(Environment.GetEnvironmentVariable("AudienceID"),clientCredential).Result;



And it was because TenantID was not resolved and thus authority value was not formed, (the Tenant which would generate token) which was expected by AuthenticationContext method.

Why it was not resolved? – The code is supposed to get the values of TenantID, ClientID, ClientSecret etc from app settings and those were missing on portal (in function app configuration-App settings). 

On local machine, local.settings.json is used to store the config values and when we publish function app to azure via Visual Studion, only dll gets uploaded to portal and not the configurations(key value pairs in localsettings file). 

Thus the configurations which were present in local.settings.json file were missing in App Settings on portal.

What to do


Here in my case, the value for authority was not available as it was not added in the app settings of the function app.

Thus after deploying the function in the function app, I went ahead and manually added the TenantID and other app configurations in Application Settings.

Thing to remember is that Local.settings.json is for testing you Azure Function locally on your machine whereas when deployed to Azure, you have to set the Application Settings under the function app for runtime 

That's it, all worked fine then after.



Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post