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.getAccount() returns null on landing page

See original GitHub issue

getAccount() returns null on landing page


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Browser:

  • Chrome version 75.0.3770.80
  • Firefox version XX
  • IE version XX
  • Edge version XX
  • Safari version XX

Library version


Library version: 1.0.0

Current behavior

msal.getAccount() returns null on landing page. Just to give you more information. I am not creating any SPA. There are 2 plain html pages with javascript - Login.html and Home.html. My requirement is to redirect user to Home page when he is successfully login.

Expected behavior

msal.getAccount() should return logined user details.

Minimal reproduction of the problem with instructions

Login.html

<!DOCTYPE html>
<html>
<head>
    <title>Login Page</title>    
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.0.min.js"></script>
    <script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.0/js/msal.js"></script>
</head>
<body>
    <h2>You are on Login Page</h2>            
    <button id="SignIn" onclick="signIn()">Sign In</button><br/><br/>    
    
    <script type="text/javascript">
    var msalConfig = {
        auth: {
            clientId: "app-id-here",
            authority: "https://login.microsoftonline.com/tenant-id-here",
            redirectUri: "http://localhost/home.html",
            navigateToLoginRequestUrl: false
        },
        cache: {
            cacheLocation: "localStorage",
            storeAuthStateInCookie: true
        }
    };

    var myMSALObj = new Msal.UserAgentApplication(msalConfig);
    myMSALObj.handleRedirectCallback(authRedirectCallBack);

    function authRedirectCallBack(error, response) {
    //Do Nothing For Now
    }

    function signIn() {
        myMSALObj.loginRedirect({"loginHint":"user@myowndomain.com",scopes: ["user.read"]});
    }

    </script>
</body>
</html>

Home.html

<h1>You are on home page</h1>
<h2 id="userName"></h2>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.0/js/msal.js"></script>
<script>    

    var msalConfig = {
        auth: {
            clientId: "app-id-here",
            authority: "https://login.microsoftonline.com/tenant-id-here",
            redirectUri: "http://localhost/home.html",
            navigateToLoginRequestUrl: false
        },
        cache: {
            cacheLocation: "localStorage",
            storeAuthStateInCookie: true
        }
    };
    var myMSALObj = new Msal.UserAgentApplication(msalConfig);

    var divWelcome = document.getElementById('userName');
    divWelcome.innerHTML = 'Welcome ' + (myMSALObj.getAccount() != null ? myMSALObj.getAccount().userName : " {Failed to authenicate} ") + " to Microsoft Graph API";    

</script>

App Registration and Configuration I have registered app as well with below configuration: image Please note I have enabled id_token and access_token in the app as well.

What I am trying to achieve? Below is the visual of what I am trying to achieve: image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonnuttercommented, Sep 25, 2019

@dipesh-wadhwa To clarify, are you still seeing this issue on 1.1.3? It has been released to the cdn (updated urls are available here).

0reactions
dipesh-wadhwacommented, Sep 26, 2019

@jasonnutter @GermanEZI @DarylThayil @sameerag @pkanher617 I have verified and this is fixed now. Brilliant…!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

msal.js 2.0 tokenResponse null after loginRedirect
At page load handleRedirectPromise() will return null , and after sign-in it should return the token. There are issues with your configuration, ...
Read more >
Single-page application: Sign-in and Sign-out - Microsoft Learn
If your application already has access to an authenticated user context or ID token, you can skip the login step, and directly acquire...
Read more >
Microsoft Authentication Library for JavaScript (MSAL.js)
The MSAL library for JavaScript enables client-side JavaScript web applications, running in a web browser, to authenticate users using Azure AD work and ......
Read more >
Cannot get MSAL account from account ID for guest users
I have a method, called from an MVC Controller, that uses a ConfidentialClientApplication to obtain credentials to connect to PowerBI. This ...
Read more >
OAuth 2.0: app.GetAccountsAsync returns null - Limilabs Q&A
We are not MSAL .NET support. Have in mind that AcquireTokenInteractive creates a new browser window or displays a login dialog (depending on...
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