我们有一个React应用,由一个单独的Identity Server站点保护。当未认证时,用户会被重定向到Identity Server的登录页面,然后在成功登录后,他们会被重定向到React应用中的回调URL。
我正在尝试尽可能地自动化这个过程,以提高我们Cypress.io测试的速度和可靠性,这样我们就不需要每次都通过UI登录--让测试成为原子式的,没有不必要的复杂性。
实现这个目标的最好方法是什么?
我已经按照Cypress团队给出的关于登录的例子,但还没能让它接近最佳。https:/github.comcypress-iocypress-example-recipestreemasterexampleslogging-in__single-sign-on.
到目前为止,我最接近的方法是按照这篇Auth0文章来做,但在填充id_token、nonce和状态值以传递给回调URL方面有欠缺。https:/auth0.comlogend-to-tend-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>
然后用响应将一个项目添加到会话存储中。
window.sessionStorage.setItem("oidc:<auth_url>:<client_id>", JSON.stringify(response));