0

I want to implement a dynamic login using msal, which includes passing the username and password in the login function and not ask for the Microsoft login prompt so that the user will log in to an account as soon as the page loads.

I have been reading a bit on the documentation on msal with react but didn't find any solutions for this problem.

This is the code I have for login. I am confused about what parameters I should pass to enable a dynamic log in for the application.

  this.userAgentApplication = new UserAgentApplication({
      auth: {
          clientId: config.appId
      },
      cache: {
          cacheLocation: "localStorage",
          storeAuthStateInCookie: true
      }
  });

var user = this.userAgentApplication.getAccount();
bheadr92
  • 33
  • 1
  • 5

1 Answers1

0

MSAL uses implicit flow for authorization and authentication.

You can request a new token from MSAL silently in code without having to ask the user every time. However, you have to detect the expired tokens manually as implicit flow doesn't support automatic refresh token endpoints. More about refreshing your tokens: docs

Related and referenced from answer: Is it possible to use MSAL.js to get refresh token?

Sarhad Salam
  • 428
  • 3
  • 12
  • That sounds good! but is there any way i can pass the username and password in the first login without the user entering it manually? I know its not the most ideal situation but its for a POC. – bheadr92 Aug 25 '19 at 02:04
  • @bheadr92 not in MSAL. According to the developers of MSAL, the library was not developed, and will not support such a use. Reference https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/75 – Sarhad Salam Aug 25 '19 at 14:58