【问题标题】:Necessity of redirection page in PKCE code flow (IdentityServer4)PKCE 代码流中重定向页面的必要性(IdentityServer4)
【发布时间】:2019-12-09 13:02:53
【问题描述】:

使用带有 IdentityServer4 的 PKCE 代码流处理项目。我在 IS4 示例中发现了这种代码的平静:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginInputModel model, string button)
{
    // check if we are in the context of an authorization request
    var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);

    // the user clicked the "cancel" button
    if (button != "login")
    {
        if (context != null)
        {
            // if the user cancels, send a result back into IdentityServer as if they 
            // denied the consent (even if this client does not require consent).
            // this will send back an access denied OIDC error response to the client.
            await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);

            // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
            if (await _clientStore.IsPkceClientAsync(context.ClientId))
            {
                // if the client is PKCE then we assume it's native, so this change in how to
                // return the response is for better UX for the end user.
                return View("Redirect", new RedirectViewModel { RedirectUrl = model.ReturnUrl });
            }

            return Redirect(model.ReturnUrl);
        }
        else
        {
            // since we don't have a valid context, then we just go back to the home page
            return Redirect("~/");
        }
    }

所以问题是我们为什么要显示重定向页面以及它如何改善用户体验? Redirec 视图上的唯一内容是消息“您现在正在返回到应用程序”。你能给我任何这样做的理由或任何必要的情况吗?谢谢!

【问题讨论】:

  • 并不是只显示一条消息。请注意刷新 meta 和 signin-redirect.js 脚本。

标签: c# asp.net authorization identityserver4 pkce


【解决方案1】:

这对于具有自定义重定向 URI 的本机客户端非常有用。如果不需要,请随意删除代码。

【讨论】:

  • 嗨,我在检查使用 IdentityServer4 的登录机制的实现时遇到了同样的问题。你能详细说明一下这个答案吗?自定义重定向 URI 在这里有什么不同? “改进的用户体验”基本上是向用户显示“您现在正在被重定向”页面之间的区别,而不是在等待重定向时导致空白页面的 302,还是还有更多?
猜你喜欢
  • 2022-11-24
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 2021-06-10
  • 2021-06-15
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多