c# - 如果存在 UseIdentityServer,是否需要 AddAuthentication 和 AddAuthorization?
问题描述
根据MSDN,我们有
负责验证请求凭据并在请求上下文中设置用户的身份验证
app.UseAuthentication()
中间件 公开 OpenID Connect 端点的 IdentityServer 中间件app.UseIdentityServer()
但是,检查后一个方法声明,我看到以下内容,在我看来,没有必要调用前者。
public static IApplicationBuilder UseIdentityServer(
this IApplicationBuilder app,
IdentityServerMiddlewareOptions options = null)
{
app.Validate();
app.UseMiddleware<BaseUrlMiddleware>();
app.ConfigureCors();
if (options == null) options = new IdentityServerMiddlewareOptions();
options.AuthenticationMiddleware(app);
app.UseMiddleware<MutualTlsEndpointMiddleware>();
app.UseMiddleware<IdentityServerMiddleware>();
return app;
}
不过,我什么也没看到UseAuthorization
。所以我的结论是,这里介绍的一般方法(即首先验证,然后授权)在我的情况下可以重新表述为以下内容。虽然我可以(应该?)跳过第二行,但我不能删除第三行(因为我[Authorize]
在项目中使用了 eg 属性)。
builder.UseIdentityServer();
//builder.UseAuthentication();
builder.UseAuthorization();
那是对的吗?
解决方案
您不需要该UseAuthentication()
部分,因为正如您在问题中提到的那样,它已经UseIdentityServer()
在引擎盖下添加了。
但是你需要保留这UseAuthorization()
部分。
推荐阅读
- c# - 如何在 C#/Unity 中访问我预定义的结构化对象中的其他元素?
- javascript - 如果键有多个单词,如何从 Firebase Realtime DB 查询数据?
- javascript - 如何在父子组件之间使用回调函数
- sql - 根据开始和结束数字生成行?
- python - 如果“key”中有空格,Python s3 copy_from 会失败。如何搜索文件内容,然后使用 python 打印存储在 S3 中的文件名
- r - 使用 Windows 批处理自动化使用 ODBC 的 R 脚本
- nginx - Nginx 配置只匹配基本路径,否则返回 404。为什么?
- ftp - 我怎样才能大规模安装 PrestaShop 模块?
- python - 美化文件夹中的所有python脚本
- reactjs - CloudFlare JS 挑战正在打破我的 SPA