【问题标题】:Cypress.io Identity ServerCypress.io 身份服务器
【发布时间】:2020-09-22 17:42:15
【问题描述】:

我们有一个受单独的 Identity Server 站点保护的 React 应用程序。未经身份验证时,用户会被重定向到 Identity Server 中的登录页面,然后在成功登录后,他们会被重定向到 React 应用程序中的回调 URL。

我正在尝试尽可能地自动化这个过程,以提高 Cypress.io 测试的速度和可靠性,这样我们就不需要每次都通过 UI 登录 - 让测试是原子的和免费的不必要的复杂性。

实现这一目标的最佳方法是什么?

我已经按照赛普拉斯团队提供的有关登录的示例进行了操作,但未能使其接近最佳状态: https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/logging-in__single-sign-on

到目前为止,我最接近的是关注这篇 Auth0 文章,但没有填充 id_token、nonce 和 state 值以传递给回调 URL: https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/

任何方向都非常感谢。

【问题讨论】:

  • 强硬的伙伴!您可以使用身份服务器请求密码令牌端点获取不记名令牌吗?然后将其注入应用程序,绕过 oidc 客户端?
  • 我可以获得访问令牌没有问题,所以如果有办法按照您的建议进行操作,那就完美了。

标签: reactjs identityserver4 cypress


【解决方案1】:

我可以通过访问 Identity Server 的 /connect/token 端点来解决这个问题:

POST /connect/token 

    client_id=client1&
    client_secret=secret&
    grant_type=password&
    username=username&
    password=password&
    scope=openid profile <client_scope>

然后使用响应将一个项目添加到会话存储中:

window.sessionStorage.setItem("oidc:<auth_url>:<client_id>", JSON.stringify(response));

【讨论】:

  • 你能在这里分享你的完整代码吗,用占位符替换你的凭据,我要看看你的实现......我面临着同样的情况,我必须通过 Cypress 登录到 Laravel 网络应用程序通过'Identity4 auth 进行身份验证,然后继续进行内页测试....
猜你喜欢
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 2015-07-22
  • 2012-11-18
  • 2015-06-23
  • 1970-01-01
相关资源
最近更新 更多