使用AspNet.Security.OpenIdConnect.Server(ASP.NET vNext)注销

使用AspNet.Security.OpenIdConnect.Server(ASP.NET vNext)注销,asp.net,jwt,openid-connect,aspnet-contrib,Asp.net,Jwt,Openid Connect,Aspnet Contrib,我正在使用Visual Studio 2015 Enterprise和ASP.NET vNext Beta8发行和使用所述的JWT代币 在我们的实现中,我们在令牌发布时将一些客户端详细信息存储在Redis中,我们希望在用户注销时刷新这些信息 我的问题是,使用OIDC注销的最佳实践是什么 虽然我可以为此使用自己的控制器,但我还是忍不住注意到OpenIDConnect(OIDC)似乎已经准备好处理这种情况了。例如,OIDC有一个onloguendpoint处理程序和loguendpointpath设

我正在使用Visual Studio 2015 Enterprise和ASP.NET vNext Beta8发行和使用所述的JWT代币

在我们的实现中,我们在令牌发布时将一些客户端详细信息存储在Redis中,我们希望在用户注销时刷新这些信息

我的问题是,使用OIDC注销的最佳实践是什么

虽然我可以为此使用自己的控制器,但我还是忍不住注意到OpenIDConnect(OIDC)似乎已经准备好处理这种情况了。例如,OIDC有一个onloguendpoint处理程序和loguendpointpath设置。但当我调用OIDC注销URI时,处理程序似乎接受我抛出的任何随机x-www-form-urlencoded表单,并且似乎没有以任何特定方式要求存在令牌


非常感谢您就正确的OIDC注销实践提供任何建议。

AspNet.Security.OpenIdConnect.Server
中,注销端点使用的逻辑留作练习

在这种情况下,它是使用MVC6控制器实现的,当然,您可以在其中自由添加自定义逻辑以从Redis服务器中删除缓存的详细信息

[HttpPost("~/connect/logout")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Logout() {
    // When invoked, the logout endpoint might receive an unauthenticated request if the server cookie has expired.
    // When the client application sends an id_token_hint parameter, the corresponding identity can be retrieved using AuthenticateAsync.
    var identity = await HttpContext.Authentication.AuthenticateAsync(OpenIdConnectServerDefaults.AuthenticationScheme);

    // Remove the cached details here. If you need to determine
    // who's the authenticated user, you can use the identity variable.

    // Remove the authentication cookie and return the user to the client application.
    return SignOut("ServerCookie", OpenIdConnectServerDefaults.AuthenticationScheme);
}
[HttpPost(“~/connect/logout”)]
[ValidateAntiForgeryToken]
公共异步任务注销(){
//调用时,如果服务器cookie已过期,注销端点可能会收到未经验证的请求。
//当客户端应用程序发送id\u token\u提示参数时,可以使用AuthenticateTasync检索相应的标识。
var identity=wait-HttpContext.Authentication.authenticateSync(OpenIdConnectServerDefaults.AuthenticationScheme);
//删除此处的缓存详细信息。如果需要确定
//谁是经过身份验证的用户,您可以使用标识变量。
//删除身份验证cookie并将用户返回到客户端应用程序。
返回注销(“ServerCookie”,OpenIdConnectServerDefaults.AuthenticationScheme);
}

您还可以直接从
LogoutEndpoint
事件执行类似操作。不要忘记调用
context.HandleResponse()
,以确保请求未被另一个中间件截获。

谢谢-只是出于好奇,如果我使用LogoutEndpoint事件,为什么端点事件需要一个表单,或者更确切地说,该表单需要什么?使用POST请求/表单不是强制性的,您还可以使用单个GET请求。我在这里使用了一个表单,因为我想向注销端点添加反XSRF支持,以防止不必要的注销(“超级注销”综合症)。或者,您也可以使用
id\u token\u hint
(仅供参考:从下一个测试版开始,我们将默认停止使用JWT访问令牌,并返回不透明令牌。有关更多信息,请参阅)确定,考虑到我们正在调用app.useJWTBeareAuthentication将使我们的OIDC实现功能保持不变,或者我们是否需要转动一些额外的旋钮以使其与JWT令牌一起工作?当迁移到beta5时,如果您不修复它,您的应用将停止工作。启用JWT令牌只需要配置委托中的一行代码。也就是说,迁移到我们新的验证/内省中间件将是推荐的方法。