Cypress & OAuth


The problem

As we know OAuth based authentication and identity plattform implementations rely on a third party. So you don’t have just your client and your server where the web application is running, but you also have a third entity which manages the authentication. This and of itself is a source of problems for Cypress, because Cypress tests are not supposed to leave the domain of the same origin.

For example if you are testing a web application of an online shop shopx.com, you are supposed to remain within that domain during your test run. But If that shop had an OAuth login mechanism using Google account for example, then it would mean that if you would try to test the Google authentication capability of that web site, you would have to leave the shopx.com domain and go to google domain and come back after authentication. But this alone would violate the Cypress rule that the domain origin should not change during the test.

Here are some examples which show we can overcome that limitation.

An example using custom commands

In this example we use the auth0.com page to create our test application with OAuth capability:

To be continued