title: Error with authentication in e2e tests using cypress: chrome-error://chromewebdata
body: <p>I'm using cypress for writing E2E tests for my UI (Note that it's a PowerBI report, hence it's kind of special case). When I am testing with a public report, it works fine. But when it's a private PBI report, I am having trouble with login part. After some research, I found this approach promising for Azure AD based auth, and added this login function in my commands.js file:</p>
  
  <pre><code>Cypress.Commands.add('login', () =&gt; { 
      cy.request({
          method: 'POST',
          url: 'https://login.microsoftonline.com/{TENANT}/oauth2/token',
          form: true,
          body: {
              grant_type: 'client_credentials',
              client_id: CLIENT_ID,
              client_secret: CLIENT_SECRET,
              // resource: RESOURCE
          },
          header: {
              'Content-Type': 'multipart/form-data'
          }
      }).then((responseData) =&gt; {
          if (responseData.status === 200) {
              window.sessionStorage.setItem("adal.idtoken", responseData.body.access_token);
              window.sessionStorage.setItem("adal.token.keys", CLIENT_ID + "|")
              window.sessionStorage.setItem(`adal.expiration.key${CLIENT_ID}`, responseData.body.expires_on)
              window.sessionStorage.setItem(`adal.access.token.key${CLIENT_ID}`, responseData.body.access_token)
          } else {
              console.log("error retrieving token")
          }
      })
  })
  </code></pre>
  
  <p>Note that the Client ID and secret are correct and have permission to access the powerbi report. I also tested the token generated, and the sessionStorage variables, and all seem to be assigned correctly. Now, in my test:</p>
  
  <pre><code>describe("E2E Tests", () =&gt; {
      beforeEach(() =&gt; {
          cy.login();
      })
      it("Sample Test 1", () =&gt; {
          cy.visit("https://powerbi-report-url.com");
          //...
      });
  })
  </code></pre>
  
  <p>And I am seeing in the cypress test runner that, even though login has been called in beforeEach, while visiting the powerbi report, it still redirects to <a href="https://login.microsoftonline.com" rel="nofollow noreferrer">https://login.microsoftonline.com</a> url with a different client id as query param, and since the superdomains of powerbi report and redirected urls are different, it gives <code>chrome-error://chromewebdata</code> error(I guess that's the reason). Hence wondering, how to login to a website in cypress tests backed by azure ad auth.</p>
  
  <p>Also, might be unrelated, but seeing one more error in the console:</p>
  
  <pre><code>Refused to display 'https://powerbi-report-url.com' in a frame because it set 'X-Frame-Options' to 'deny'.
  </code></pre>
  
  <p>Edit 1: Switching to Edge doesn't give the chrome webdata error, but still the cy.visit to the URL times out and gives HTTP 431 Error(Request header too long) and couldn't authenticate.</p>
  
  <p>Edit 2 (More Details about Auth Error): While generating the toke using client credentials, I am getting the token, and see it's stored in the session Storage, however the cypress tests are not picking the same token to authorize the visit to PowerBI report. So, basically even thought the cookie exist to auth the request, the request to Power BI visit still redirects to login.microsoftonline.com/common/oauth2/authorize?client_id={a different client ID from what I am using in the above POST call}</p>
  
  <p>Whereas, while using username/password; getting this error: "error": "interaction_required", "error_description": "AADSTS50079: Due to a configuration change made by your administrator, or because you moved to a new location, you must enroll in multi-factor authentication to access
  "error_codes": [50079]</p>