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.

getAccount in @azure/msal-browser": "^2.0.0"

See original GitHub issue

Library

  • msal@1.x.x or @azure/msal@1.x.x
  • @azure/msal-browser@2.x.x
  • @azure/msal-angular@0.x.x
  • @azure/msal-angular@1.x.x
  • @azure/msal-angularjs@1.x.x

Description

In the version 2.x.x of the msal-browser library, getAccount() was removed. In issue #1843 it was mentioned that we can ensure that at any moment there is only one logged in user in our application by doing this:

If you want to ensure your application is always a single account application, you can do that yourself by ensuring you don’t present a sign-in screen after the initial login.

If I understand correctly, this is not always possible to ensure by just not presenting the sign-in screen after the initial login in my application. For example, if I use my admin Azure AD user to login to portal.azure.com and then I go to my own application and try to log in with my personal user from AD, MSAL.js will keep track of both accounts, even though one of the logins didn’t happen in my own application, it happened in azure portal. Is that right?

Is there any piece of documentation on how to achieve the same single account behavior that we had in MSAL v1 using loginPopup?

I agree with @jrmcdona that it would be nice if MSAL provided an API to keep track of an user session, as it did before. For us, is a stopper for going to v2.x.x

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
deasemscommented, Sep 10, 2020

Thanks for the info @pkanher617.

The expected behavior in my app is that the user that signed in most recently is the account that will be used in my app (this isn’t really an explicit requirement, rather just maintaining the behavior from pre-v2). I’m interested in the specifics of MSAL’s account APIs because it seems in this multi-user world it’s technically possible to not select the most recent signed in account.

The scenario I see this inadvertently happening in is when resuming an existing session (which we’d like to do as much as possible for perf). In this scenario I’d call getAllAccounts and if length > 0, choose the first entry. Now if the order of the returned array isn’t guaranteed then it seems possible to get any old account.

Now of course we can track accounts used in our app and add logic to ensure we choose the right account, that just increases the effort needed to adopt v2 and I can imagine it’s easy to get that wrong, hence I see value in a getAccount api.

1reaction
deasemscommented, Sep 1, 2020

Then if User Two logs into App A, getAllAccounts for App A will return multiple accounts (User One and Two’s).

@technical-boy Is there a guaranteed order to the getAllAccounts array? In this scenario, what order would user one and two be in in this array?

I’d like to agree that having support for a ‘single user mode’ would be very convenient (and I think would be the common case given apps need to implement extra UI for multi-user scenarios).

Read more comments on GitHub >

github_iconTop Results From Across the Web

@azure/msal-browser - npm
A vanilla JavaScript sample showing basic usage of the MSAL 2.0 library ( @azure/msal-browser package) with the Microsoft Graph API. npm start ...
Read more >
msal.js 2.0 tokenResponse null after loginRedirect
I am using msal.js 2.0 @azure/msal-browser to log into B2C and retrieve id and access tokens using code flow. I set up my...
Read more >
Ember Js Tutorial: Typeerror: Cannot Read Property 'Maps' Of ...
How do I incorporate @azure/msal-browser to use the loginRedirect? ... getAccount() returns null on landing page · Issue #758 Authenticate azure python ...
Read more >
setting username and email in git Code Example
... No matching distribution found for tensorflow==2.0.0 · angular cli global update ... bash count character in variable · npm@azure/msal-browser 2.3.0 ...
Read more >
Msal acquiretokensilent refresh token angular
The npm package @azure/ msal -browser receives a total of 561,029 downloads a ... If you use the MSAL Guard, it will check...
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