ASP.Net MVC6 是否支持 OAuth 2 不记名令牌?

Does ASP.Net MVC6 support OAuth 2 bearer tokens?

我正在使用 ASP.Net MVC6 开发应用程序,我想使用不记名令牌实现 OAuth 2 身份验证。我找不到任何关于这是否可能的可靠信息。谁能给我指出正确的方向?

TL;DR: Microsoft 为 ASP.NET Core 开发的官方包仅支持 OAuth2 不记名令牌验证。

这意味着...

  1. ...您将能够使用外部身份提供者(如 Azure Active Directory)颁发的不记名令牌和 Microsoft.AspNetCore.Authentication.JwtBearer 包对您的用户进行身份验证:

    app.UseJwtBearerAuthentication(new JwtBearerOptions
    {
        AutomaticAuthentication = true,
        Audience = "http://localhost:50000/",
    
        // Authority is only useful if your JWT tokens
        // are issued by an OpenID Connect server.
        Authority = "[OpenID Connect provider address]",
    
        // If you don't use an OpenID Connect server, you have to manually update the
        // token validation parameters with the issuer's signing key.
        TokenValidationParameters = new TokenValidationParameters
        {
            IssuerSigningKey = new X509SecurityKey(certificate)
        }
    });
    

也就是说,现在仅支持 JWT 令牌 OTB:Katana 3 随附的 OAuth2 承载中间件用于原生支持 OAuth2 授权服务器生成的不透明令牌,但此支持已被删除。

  1. ...您将无法再生产自己的代币。 OAuth2 授权服务器已被删除,不会移植到 ASP.NET 核心:.

幸运的是,存在替代方案。我个人正在开发基于 Katana 附带的 OAuth2 服务器的 OpenID Connect 服务器中间件,它提供相同的低级体验:https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server

有关更多信息,您可以查看此 SO 答案: