azure - Azure Function V2 JWT - AD 身份验证
问题描述
我正在尝试对 Azure Functions v2 进行身份验证。我得到以下错误
Microsoft.AspNetCore.Authentication.Core: No authentication handler is registered for the scheme 'WebJobsAuthLevel'. The registered schemes are: Bearer. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("WebJobsAuthLevel",...)?.
下面是我在 Startup.cs 中使用的代码
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
builder.Services.AddAuthentication()
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme,o =>
{
o.Audience = "https://*******************.azurewebsites.net/";
o.Authority = "http://localhost:****";
o.RequireHttpsMetadata = false;
o.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
RequireSignedTokens = true,
ValidAudience = "https://***************.azurewebsites.net/",
ValidateAudience = true,
ValidIssuer = "https://sts.windows.net/***************-5********2**/",
ValidateIssuer = true,
ValidateIssuerSigningKey = true,
ValidateLifetime = true
};
});
}
}
更改了代码,但仍然得到相同的给定错误。我错过了哪一个?
解决方案
考虑使用Azure 应用服务身份验证/授权功能(也非正式地称为 EasyAuth)。如果您遵循 Azure 门户中的快速流程,它将为您的函数应用程序创建一个 AAD V1 应用程序注册,并自动配置您的应用程序以允许使用 AAD 进行身份验证。如果您随后设置Action to take when request is not authenticated
为Login with Azure Active Directory
,则只有经过身份验证的请求才会被授权向您的应用程序发出任何请求。
EasyAuth 已内置支持接受承载令牌以进行 AAD 应用程序注册,以及 AAD 和我们其他支持的身份提供商(Facebook、Google、Twitter)的一些其他 OAuth2/OIDC 流程。通过此功能,您不需要添加任何代码,这一切都将由 Azure 平台处理。
推荐阅读
- python - 通过python发送HTML电子邮件,格式错误
- .net - AzureFunctionapp APPSETTING_ 被追加
- html - 我的 wordpress 主页上的社交媒体图标在 OceanWP 主题上使用 FontAwesome 正确显示
- android - 是否可以在给定的时间段内使用 firebase 控制台向所有用户统一发送推送通知?
- python - Scipy 像 Excel Solver 一样最小化
- ios - 资产中的 HEIC 图像生成“CompileAssetCatalog 失败,退出代码为非零”
- asynchronous - Dart 在异步修改主体上的 runZoned() 行为
- android - 在 Android 中实现应用程序更新功能
- php - 如果 opcache 是打开的,为什么我的新代码即使没有任何 php-fpm 重启也能工作?
- azure - 如何监控 AKS pod 可用性 cpu 和内存利用率?