I tried
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var azureAdConfig = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"AzureAd:Instance", "https://login.microsoftonline.com/"},
{"AzureAd:ClientId", "xxx"},
{"AzureAd:TenantId", "xxx"}
})
.Build();
builder.Services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddMicrosoftIdentityWebApi(azureAdConfig)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddInMemoryTokenCaches();
and in the function
[Authorize]
[FunctionName("getStuff")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
I’m passing the token from the front but I get a 500
and in the console (backend) I see
[2024-06-06T10:37:58.854Z] An unhandled host error has occurred.
[2024-06-06T10:37:58.855Z] Microsoft.AspNetCore.Authentication.Core: No authentication handler is registered for the scheme ‘WebJobsAuthLevel’. The registered schemes are: Bearer. Did you forget to call AddAuthentication().AddSomeAuthHandler?.
[2024-06-06T10:37:59.279Z] Host lock lease acquired by instance ID ‘0000000000000000000000006A9C9842’.