隔离的Azure函数缺少身份验证标头?
我创建了一个新的.NET 6隔离的Azure函数,然后是这篇文章: https://joonasw.net/view/azure-ad-jwt-authentication-in-net-isolated-process-azure-functions
如果我在本地调试,它可以很好地工作,它可以很好地工作,客户端将身份验证标头附加到我可以在身份验证中间件中阅读的请求。但是,一旦将功能应用程序部署到Azure中,我将无法访问身份验证中间件中的身份验证标头,则缺少此标头条目。看起来身份验证标头以某种方式从标题中删除。
我的程序是
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder =>
{
builder.UseNewtonsoftJson();
builder.UseMiddleware<AuthenticationMiddleware>();
builder.UseMiddleware<AuthorizationMiddleware>();
builder.UseMiddleware<ExceptionHandlerMiddleware>();
builder.Services.AddOptions<AppSettings>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection("AppSettings").Bind(settings);
});
builder.Services.AddPersistenceRepositories();
builder.Services.AddPersistenceServices();
builder.Services.AddPersistenceInfrastructures();
builder.Services.AddSingleton<IHttpFunctionExecutor, HttpFunctionExecutor>();
})
.ConfigureOpenApi()
.Build();
host.Run();
}
I have created a new .NET 6 Isolated Azure Function followed by this great article:
https://joonasw.net/view/azure-ad-jwt-authentication-in-net-isolated-process-azure-functions
If I'm debugging it locally, it works perfectly, the calling client attaches an authentication header to the request which I can read in the authentication middleware. But once the function app is deployed in Azure, I cannot access the authentication header in the authentication middleware, this header entry is missing. It looks like the authentication header is somehow removed from the header.
My program is
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder =>
{
builder.UseNewtonsoftJson();
builder.UseMiddleware<AuthenticationMiddleware>();
builder.UseMiddleware<AuthorizationMiddleware>();
builder.UseMiddleware<ExceptionHandlerMiddleware>();
builder.Services.AddOptions<AppSettings>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection("AppSettings").Bind(settings);
});
builder.Services.AddPersistenceRepositories();
builder.Services.AddPersistenceServices();
builder.Services.AddPersistenceInfrastructures();
builder.Services.AddSingleton<IHttpFunctionExecutor, HttpFunctionExecutor>();
})
.ConfigureOpenApi()
.Build();
host.Run();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢您 @ jack.pop 的解决方案,发布与答案相同,以便其他社区成员可以为类似的问题提供好处。
解决方法: -
有关更多信息,请参阅此博客| 隔离的Azure函数缺少身份验证标头和身份 。
Thank you @jack.pop ,For the solution ,Posting the same as answer so that other community members can beneficial for similar issue.
WORKAROUND:-
For more information please refer this Blog|Isolated Azure Function missing authentication header and identity .