我们有一个由单独的 Identity Server 站点保护的 React 应用程序。如果未经身份验证,用户将被重定向到 Identity Server 中的登录页面,然后在成功登录后,他们将被重定向到 React 应用程序中的回调 URL。
我试图尽可能地自动化这个过程,以提高我们 Cypress.io 测试的速度和可靠性,这样我们就不需要每次都通过 UI 登录——允许测试是原子的,没有不必要的复杂性.
实现这一目标的最佳方法是什么?
我遵循了 Cypress 团队提供的有关登录的示例,但未能使其接近最佳状态:
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/
任何方向都非常感谢。
最佳答案
我可以通过点击 /connect/token
来解决这个问题。身份服务器的端点:
POST /connect/token
client_id=client1&
client_secret=secret&
grant_type=password&
username=username&
password=password&
scope=openid profile <client_scope>
然后使用响应将项目添加到 session 存储中:
window.sessionStorage.setItem("oidc:<auth_url>:<client_id>", JSON.stringify(response));
关于reactjs - Cypress.io 身份服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62182770/