title: Using Cypress to Test an App That Relies on OAuth
body: <p>I've inherited a Node.js web app that uses relies on OAuth. Whenever you visit a page the app ensures you've authenticated. Please note, there no Angular, React, Vue, etc here. Each page is straight up HTML.</p>
  
  <p>I want to test this site using <a href="https://www.cypress.io/" rel="noreferrer">Cypress</a>. My problem is, I'm stuck on the initial redirect from the auth provider. Cypress acknowledge <a href="https://docs.cypress.io/guides/references/known-issues.html#OAuth" rel="noreferrer">OAuth is a challenge</a>.</p>
  
  <p><strong>commands.js</strong></p>
  
  <pre><code>Cypress.Commands.add('login', (credentials) =&gt; {
    var settings = {
      'clientId':'&lt;id&gt;',
      'scope':'&lt;scope-list&gt;',
      ...
    };
  
    var body = `client_id=${settings.clientId}&amp;scope=${settings.scope}...`;
  
    var requestOptions = {
      method: 'POST',
      url: 'https://login.microsoftonline.com/...',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: body
    }
  
    cy.request(requestOptions);
  });
  </code></pre>
  
  <p>Then, in my test, I have:</p>
  
  <pre><code>context('Home', () =&gt; {
    it('Visits Successfully', () =&gt; {
      cy.login();
  
      cy.title().should('include', 'welcome');
    });
  });
  </code></pre>
  
  <p>In the test runner, I see the login POST request is occurring. I confirmed that an access token is being received using a <code>console.log</code>, however, my title is empty. It's like the redirect after OAuth isn't happening in Cypress. However, when I visit the site in the browser, the redirect is happening as expected.</p>
  
  <p>What am I missing?</p>