Hi anonymous user,
I haven't implemented this personally, but based on my research it appears that this is something you can do.
There is a blog post here by Jan Hajek where the author provides an example of adding builder.Services.AddAuthentication() in the functionstartup class.
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
// This is configuration from environment variables, settings.json etc.
var configuration = builder.GetContext().Configuration;
builder.Services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = "Bearer";
sharedOptions.DefaultChallengeScheme = "Bearer";
})
.AddMicrosoftIdentityWebApi(configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddInMemoryTokenCaches();
}
}
}
Based on some previous Github issues, it looks like support for this didn't exist before but was since added.
https://github.com/Azure/azure-functions-host/issues/6805
https://github.com/Azure/azure-functions-host/issues/4485
https://github.com/Azure/azure-functions-host/issues/5886
There is also a nuget package that was published for handling this scenario. https://www.nuget.org/packages/AzureFunctions.Authentication/
Let me know if you have any issues with the implementation, though.
-
If the answer provided was helpful to you, please remember to "mark as answer" so that others in the community searching for similar information can more easily find a solution.