reactjs - Cypress.io 身份服务器

标签 reactjs identityserver4 cypress

我们有一个由单独的 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/

相关文章:

python - 在 ReactJS 上使用 django Web 应用程序后端和移动应用程序

javascript - 使用 gatsbyjs 创建网站时遇到问题

javascript - 使用 Materialize 添加自定义样式以响应元素

reactjs - 在 create-react-app 中高效导入多个相似的 svg 源?

java - 具有 Web API 的 JWT Introspection 中间件 - Java 和 Identity Server

c# - 如何在 .NET 4.6 上使用 .NET Core 的 IdentityServer4?

javascript - Cypress 通过部分元素名称查找元素

reactjs - Cypress 中的 process.env 空对象

.net - Identity Server 4 和用于用户管理的 Web API

cypress - 为什么访问 api.cypress.io 端口 443 时,Cypress 会得到 ECONNRESET?