Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I automate Azure AD login in my automated integration test? #6293

Closed
tcb1978 opened this issue Aug 7, 2023 · 2 comments
Closed
Assignees
Labels
msal-browser Related to msal-browser package msal-react Related to @azure/msal-react Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days question Customer is asking for a clarification, use case or information.

Comments

@tcb1978
Copy link

tcb1978 commented Aug 7, 2023

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

2.38.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

none

Public or Confidential Client?

Confidential

Description

I am testing an app that relies on MSAL React! Our app uses UnauthenticatedTemplate and AuthenticatedTemplate components -- if the Unauthenticated component loads, our app immediately redirects to the logon.microsoft.com/tenantID URL. This redirect is what we are trying to prevent by having our e2e test first establish a valid session, and then after that, our e2e test navigates to our app hosted on localhost (and that app should detect we already have a session, and thus not redirect).

My team came to the conclusion today that client_credentials isn't the correct grant type for our use case. It's not similar enough to a user logging in. So we're exploring using a test user account credential with the password grant_type instead, now.

We're trying to get something like the below code working. The main problem we're having, is after getting the response back, how should we save the token into sessionStorage correctly? Saving to id_token as below is wrong - msal-react seems to save several token key names, and I am not sure how to generate that list of token keys properly

Cypress.Commands.add("aadAuthenticate", window => {
const clientId = "my-client-id";
const tenantId = "my-tenant-id";
const clientSecret = "my-secret";

cy.request({
    method: "POST",
    url: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`,
    header: {
        "cache-control": "no-cache",
        "Content-Type": "application/x-www-form-urlencoded"
    },
    form: true,
    body: {
        client_id: clientId,
        client_secret: clientSecret,
        username: "[email protected]",
        password: "test-pw",
        grant_type: "password",
        scope: "api://my-app.com/app.Read openid profile"
    }
}).then(response => {
    const token = response.body.access_token;
    window.sessionStorage.setItem("id_token", token);
});

});

MSAL Configuration

No response

Relevant Code Snippets

No response

Identity Provider

Azure AD / MSA

Source

Internal (Microsoft)

@tcb1978 tcb1978 added the question Customer is asking for a clarification, use case or information. label Aug 7, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Aug 7, 2023
@github-actions github-actions bot added confidential-client Issues regarding ConfidentialClientApplications msal-browser Related to msal-browser package msal-react Related to @azure/msal-react labels Aug 7, 2023
@jo-arroyo
Copy link
Collaborator

@tcb1978 I see that you have copied a comment from #4519 as your issue. Have you read the rest of the guidance provided on that issue, as well as looked into our testing doc that details the loadExternalTokens API and testing sample?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Aug 9, 2023
@microsoft-github-policy-service
Copy link
Contributor

@tcb1978 This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale.

@microsoft-github-policy-service microsoft-github-policy-service bot added the no-issue-activity Issue author has not responded in 5 days label Aug 15, 2023
@bgavrilMS bgavrilMS removed the confidential-client Issues regarding ConfidentialClientApplications label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msal-browser Related to msal-browser package msal-react Related to @azure/msal-react Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

3 participants