question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[msal-react] How should I automate Azure AD login in my automated integration test?

See original GitHub issue

Core Library

MSAL.js v2 (@azure/msal-browser)

Core Library Version

2.21.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

1.2.0

Description

I am working on an automated test (e.g. using Cypress or Selenium) that needs to initially get pass the Azure AD login screen.

In this test, I am able to make a POST request to https://login.microsoftonline.com/my-tenantId/oauth2/v2.0/token with the grant type client_credentials and a client_id and client_secret. I get a token back.

However, I don’t understand how I should save this token into the sessionStorage so that when my Cypress test visits localhost:8080, I avoid the redirect to login again. I would prefer my test to not use an email/password to login (and instead use the client credentials).

When I look at how msal-react updates the sessionStorage in my real-world browser runtime, I see quite a few MSAL tokens being saved into session storage. I don’t understand if I need to get all of these using POST requests.

Am I going about automating this the wrong way? Would love some guidance or direction on which documentation I should read for my use case. Thanks!

MSAL Configuration

No response

Relevant Code Snippets

No response

Identity Provider

Azure AD / MSA

Source

External (Customer)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
whatjakecodescommented, Feb 23, 2022

Yes, please mark it resolved. Appreciate your support, @hectormmg !

1reaction
hectormmgcommented, Feb 18, 2022

@whatjakecodes I’ve been looking further into your approach, and I think you should check out the testing doc we have on using loadExternalTokens API. What you originally wanted to do is achievable through this advanced API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run automated integration tests - Microsoft Entra
From your app registration in the Azure portal, go to Authentication > Advanced settings > Allow public client flows. Set the toggle to...
Read more >
GitHub - Mimetis/msal-react-tester
MSAL React Tester is a NPM package to allows you creating unit tests for any of your components that need to be authenticated...
Read more >
Testing Azure AD-protected APIs, part 3 - Joonas Westlin
In the third part we look at how we might build automated integration tests against an Azure AD-protected API.
Read more >
How to acquire and use an access token from Azure AD in a ...
Recently, I wrote an article on how to How to set up SSO authentication and RBAC with Azure AD in a React web...
Read more >
e2e testing - How to use Microsoft Authentication Library ...
The domain based integrated authentication will eventually be supported. ... grant is that the Azure AD v2.0 endpoint will not support it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found