【问题标题】:IdentityServer4 with SPA and hellojs带有 SPA 和 hellojs 的 IdentityServer4
【发布时间】:2019-06-29 04:35:27
【问题描述】:

我基于 dotnet new 模板“IdentityServer4 Quickstart UI (UI assets only)”(is4ui) 创建了一个 IdentityServer。

这与服务器渲染的 MVC 应用程序一起工作得很好,但我无法让它与使用 hellojs 的 SPA 一起工作。

我正在摆弄 url 以从 Identity Server 显示登录页面。登录逻辑运行良好,但我认为缺少任何小块以正确地使用访问令牌重定向到我的客户端应用程序。

这是我用来初始化 hellojs 的代码:

const AuthorityUrl = 'http://localhost:5000';
hello.init({
  'openidconnectdemo': {
    oauth: {
      version: '2',
      auth: AuthorityUrl + '/Account/Login',
      grant: AuthorityUrl + '/Grant'
    },
    scope_delim: ' '
  }
});

hello.init({
  openidconnectdemo: this.authConfig.clientId
});

这是登录密码

hello.login('openidconnectdemo', {
  redirect_uri: this.authConfig.redirectUrl,
  scope: `openid profile`,
  response_type: 'token',
  display: 'page',
});

在 AccountController 中的这段代码中,Identity Server 尝试重定向到应用程序,但由于 ReturnUrl 为空而失败:

                if (Url.IsLocalUrl(model.ReturnUrl))
                {
                    return Redirect(model.ReturnUrl);
                }
                else if (string.IsNullOrEmpty(model.ReturnUrl))
                {
                    return Redirect("~/");
                }
                else
                {
                    // user might have clicked on a malicious link - should be logged
                    throw new Exception("invalid return URL");
                }

我是否必须修改 Identity Server 才能让它们一起工作,还是客户端部分缺少某些东西?

感谢您的建议!

【问题讨论】:

    标签: single-page-application identityserver4 openid-connect hello.js


    【解决方案1】:

    我可能会推荐使用 oidc-client-js,因为它是 OIDC 的完整实现,应该更容易上手。

    也就是说,您的第一个问题似乎是身份验证 URL 应该指向授权端点而不是 UI 中的登录 - 即它应该是 /connect/authorize 而不是 /account/login

    【讨论】:

    • 感谢您的反馈。最后我选择了 angular-oauth2-oidc,这在当时非常简单。
    猜你喜欢
    • 2018-08-10
    • 2020-04-16
    • 2020-08-31
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    • 2018-02-22
    相关资源
    最近更新 更多