Error when testing with Cypress

Problem Statement

We want to build a test for the login, including SSO, with Cypress, but the login fails after entering the credentials.

Symptoms

Users might observe below issues:

  • Error 403 Forbidden when the test continues without the authentication
  • Blank screen in some cases (page never loads)

Cause

Some parts of this snippet may not be right. Below is the snippet:

Cypress.Commands.add('login', (overrides = {}) => {
  Cypress.log({
    name: 'loginViaAuth0',
  });

  const options = {
    method: 'POST',
    url: Cypress.env('auth_url'),
    body: {
      grant_type: 'password',
      username: Cypress.env('auth_username'),
      password: Cypress.env('auth_password'),
      audience: Cypress.env('auth_audience'),
      scope: 'openid profile email',
      client_id: Cypress.env('auth_client_id'),
      client_secret: Cypress.env('auth_client_secret'),
    },
  };
  cy.request(options);
});
  1. It is required to use ROPG (“password” grant type). This cannot work with the Authorization Code currently. Please check the Cypress updates.
  2. Audience must be a valid API for the application (client ID) selected
  3. It must contain the client secret.

Please benoted that testing with Cypress is only available with Auth0 DB connections currently.

Solution

Cypress is an external library and is out of our scope, so check their documentation instead:

Here are some help docs: