问题描述
我正在使用 velusia 示例,我希望客户端应用程序跳过注销提示页面,是否有任何特定方法可以实现这一点,还是应该自己实现?
解决方法
根据你的描述,我建议你可以尝试设置一个js代码在服务器端自动点击注销按钮。
更多细节,您可以参考以下代码:
修改服务器的注销视图如下:
@using Microsoft.Extensions.Primitives
<div class="jumbotron">
<h1>Log out</h1>
<p class="lead text-left">Are you sure you want to sign out?</p>
<form asp-controller="Authorization" asp-action="Logout" method="post">
@* Flow the request parameters so they can be received by the LogoutPost action: *@
@foreach (var parameter in Context.Request.HasFormContentType ?
(IEnumerable<KeyValuePair<string,StringValues>>) Context.Request.Form : Context.Request.Query)
{
<input type="hidden" name="@parameter.Key" value="@parameter.Value" />
}
<input class="btn btn-lg btn-success" id="Confirm" name="Confirm" type="submit" value="Yes" />
</form>
</div>
@section scripts{
<script>
$(document).ready(function() {
console.log("Fired");
document.getElementById("Confirm").click();
});
</script>
}
,
您如何处理注销请求取决于您。要在不显示同意书的情况下触发到客户端应用程序的重定向(当设置了 post_logout_redirect_uri
时),请触发指向 OpenIddict 的 ASP.NET Core Logout
操作:
// Returning a SignOutResult will ask OpenIddict to redirect the user agent
// to the post_logout_redirect_uri specified by the client application or to
// the RedirectUri specified in the authentication properties if none was set.
return SignOut(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,properties: new AuthenticationProperties
{
RedirectUri = "/"
});
也就是说,我不建议这样做:不需要用户同意或某种形式的防伪保护 - id_token_hint
可以提供帮助,使用 AuthenticateAsync()
从中检索主体 - 可能使有针对性的 DOS 攻击成为可能。