asp.net 核心 WEB API 中的身份验证和授权

Authentication and Authorization in asp.net core WEB API

我是asp.net核心的新手,想在WEBAPI2项目中实现认证授权。我有点混淆使用 基本身份验证、不记名令牌、JWT 令牌 或任何其他。请建议更可取 谢谢

Basic auth 顾名思义,非常基础但不是很安全,它使用 base64 编码的用户名和密码,所以如果你使用它必须使用 HTTPS,但最好不要使用它。

不记名令牌是一种令牌,它有效地向令牌的“不记名者”提供资源访问权限。 basic 和 bearer 都用于 HTTP 授权 header.

您可以使用不同格式的不记名令牌,其中一种是 JWT - JWT 是行业标准,因此我建议您使用它,因此您将使用不记名令牌。

This article is a good starting point to look into all this in the context of asp.net core. See also this video series and this article 详细介绍了 JWT 验证。

编辑

在评论中回答您的问题:

OAuth is a standard for users to delegate permissions to apps or websites to access their resources, for example when you allow some web app to post on your behalf to your Facebook feed. Various tokens are used in this process and they're very often JWT. OAuth2 adds authentication via OpenID Connect.

另一方面,

OWIN 是 Web 服务器的标准,它将 IIS 和 ASP.NET 分离,目的是允许 ASP.NET 到 运行 在其他 Web 服务器上如果这些框架与 OWIN 兼容,则通常在 OWIN 兼容服务器上 运行 实施 OWIN 和其他框架。

Auth0 is an identity platform which can do OAuth and allows you to use JWTs, generally it handles your identity and SSO. IdentityServer 是另一个具有一些类似功能的身份平台。

我仍然建议从我在顶部链接的文章开始,不要太担心 OWIN,阅读更多关于 OAuth 的信息以确定您是否真的需要它。如果你这样做,我会推荐 IdentityServer。

ASP.NET Core 2.0及以上Web API 认证授权

承载类型基于 JWT 令牌的身份验证

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]

请按如下执行post

https://fullstackmark.com/post/13/jwt-authentication-with-aspnet-core-2-web-api-angular-5-net-core-identity-and-facebook-login