ASP.Net MVC6是否支持OAuth 2承载令牌?

时间:2015-06-23 15:45:47

标签: asp.net oauth-2.0 asp.net-core-mvc

我正在使用ASP.Net MVC6开发一个应用程序,我想使用bearer令牌实现OAuth 2 auth。我无法找到关于这是否可能的任何可靠信息。有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:7)

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)
        }
    });
    
  2. 也就是说,现在只支持JWT令牌OTB:Katana 3附带的OAuth2承载中间件本身支持OAuth2授权服务器生成的不透明令牌,但此支持已被删除。

    1. ......你将不再能够制作自己的代币。 OAuth2授权服务器已被删除,不会移植到ASP.NET Core:OAuth Authorization Service in ASP.NET Core
    2. 幸运的是,存在替代方案。我个人正在开发一个基于Katana附带的OAuth2服务器的OpenID Connect服务器中间件,它提供相同的低级别体验:https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server

      有关详细信息,您可以查看此SO答案:Configure the authorization server endpoint