I'm looking to allow a UI test to bypass login via a token I'm getting from a REST request to login.microsoft.com. I have the response coming back with a valid token but am unable to populate the browser so my "user" is logged in on page load. I'm currently leveraging Cypress to validate the application and am using the below method to get my token and populate local storage and a cookie.
Cypress.Commands.add("login", () => { cy.request({ method: "POST", url: `https://login.microsoftonline.com/${Cypress.config( "tenantId" )}/oauth2/token`, form: true, body: { grant_type: "client_credentials", client_id: Cypress.config("clientId"), client_secret: Cypress.config("clientSecret"), resource: Cypress.config("clientId"), }, }).then((response) => { cy.log("RESPONSE: " + JSON.stringify(response.body)) const Token = response.body.access_token Cypress.config("Token", Token) localStorage.setItem(`{ "authority":"https://login.microsoftonline.com/${Cypress.config("tenantId")}/", "clientId": "${Cypress.config("clientId")}"}`, `{"accessToken":"${Token}","idToken":"${Token}", "expiresIn": "${response.body.expires_on}"}`) localStorage.setItem(`msal.${Cypress.config("clientId")}.idtoken`,`${Token}`) cy.setCookie(`msal.${Cypress.config("clientId")}.idtoken`,`${Token}`); }); });
Does anybody know what the browser needs to consider a user authenticated?