.net - 将 Windows 身份验证与 OAuth 2.0 结合使用

标签 .net oauth-2.0 single-sign-on windows-authentication owin

我已经设置了一个 OWIN 授权服务器和多个公开 ASP.NET Web API 的资源服务器。我正在从授权服务器提供一个特定于每个资源服务器的 JWT(其想法是每个资源服务器都需要将自定义声明封装在其 token 中)。

这些服务器都位于 Intranet 环境中,我们过去曾使用 Windows 身份验证 (Kerberos) 来提供单点登录体验。此功能在我的实现中已丢失,因为我使用用户的用户名和密码(根据 AD 进行身份验证)来授予 token 。我想知道是否有一种方法可以恢复单点登录体验 - 也许可以在授予用户 token 之前使用 Windows 身份验证来建立用户的身份?

我觉得这有点不正统,而且可能很愚蠢 - 所以请告诉我是否有更好的替代方法来在内网环境中使用 OAuth 2.0 实现 SSO。

最佳答案

事实证明,这并不像我想象的那么难。我从替代端点 (/token/windows/) 创建了一个标准 Web API Controller 。此端点采用带有 Windows 用户尝试连接的客户端(资源)ID 的 HTTP POST。我将标准 [Authorize] 属性放在操作上以确保建立身份,然后手动创建声明身份并将 JWT 返回给用户。从那时起,用户使用标准 token 刷新过程。

编辑:下面是一个示例,代表了我所实现的内容。请注意,此应用程序在 IIS 中配置为支持 Windows 身份验证(除了匿名身份验证之外):

[RoutePrefix("token/windows")]
public class WindowsAuthenticationController : ApiController
{
    [Authorize]
    [HttpPost]
    [Route("{client_id}"]
    public async Task<IHttpActionResult> CreateTokenForWindowsIdentity(string client_id)
    {
        var user = User as ClaimsPrincipal;
        if (user == null) return Unauthorized(); //401
        var claims = //generate claims based on the User.Identity.Name...
        var identity = new ClaimsIdentity("JWT");
        identity.AddClaims(claims);

        //manually create JWT using whatever method you prefer,
        //I used something inspired from http://bitoftech.net/2015/02/16/implement-oauth-json-web-tokens-authentication-in-asp-net-web-api-and-identity-2/
    }
}

关于.net - 将 Windows 身份验证与 OAuth 2.0 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27217424/

相关文章:

oauth-2.0 - 在门户中哪里可以获取我的 Azure AD B2C 发行人 URL

ldap - Shibboleth IDP 无法解析属性

android - 在项目 'app' 中,已解决的 Google Play 服务库依赖项依赖于另一个确切版本(例如 "[1.3.1 ,2.3]",

c# - 取消选择 DataGridView 上的所有行

.net - Thread.Sleep 是否会停用 TCPListener?

c# - 四舍五入和填充小数

c# - 使用 MobileServiceClient 和 SingleSignOn 身份验证的问题

.net - 如何获取 ClickOnce 应用程序的文件夹路径

java - Spring中如何实现基于客户端 token 的限速?

oauth - Outlook Office 365 : Refresh token failed to retrieve because "AADSTS70000" the provided value for the 'code' parameter is not valid