smd
smd

Reputation: 352

Cypress.io Identity Server

We have a React application protected by a separate Identity Server site. When unauthenticated, the user is redirected to the login page within Identity Server and then on successful login they are then redirected to a callback URL within the React application.

I'm trying to automate this process as much as possible to improve the speed and reliability of our Cypress.io tests so that we don't need to login via the UI each time - allowing the tests to be atomic and free of unnecessary complexity.

What would be the best way to achieve this?

I've followed the examples the Cypress team give around logging in, but haven't been able to get it close to optimal: https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/logging-in__single-sign-on

The closest I've come so far is by following this Auth0 article, but fell short of populating the id_token, nonce and state values to pass to the callback URL: https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/

Any direction greatly appreciated.

Upvotes: 4

Views: 2245

Answers (1)

smd
smd

Reputation: 352

I was able to get around this by hitting the /connect/token endpoint of the Identity Server:

POST /connect/token 

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

And then used the response to add an item into session storage:

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

Upvotes: 5

Related Questions