AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.64k stars 2.64k forks source link

Node CLI with MSAL node authentication fails with “No loop back server exists” error #6945

Open 2strokes opened 7 months ago

2strokes commented 7 months ago

Core Library

MSAL Node (@azure/msal-node)

Core Library Version

2.6.4

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

2.0.12

Public or Confidential Client?

Public

Description

I have a node cli application and uses msal-node to acquire a token. I’m able to fetch a token successfully but it keeps crashing with the error “no_loopback_server_exists”. And this happens to be in the file - LoopbackClient.js “throw NodeAuthError”.

Error Message

“no_loopback_server_exist“

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

MSAL Configuration

{

auth:{

   ClientId:””
   authority:””
   redirectUri:””
}
}

Relevant Code Snippets

const acquireToken = async () => {
    const accounts = await pca.getTokenCache().getAllAccounts();
    if (accounts.length === 1) {
        // Try to acquire token silently for the single account.
        // If silent acquisition fails, use interactive authentication.
        const silentRequest = {
            account: accounts[0],
        };
        return pca.acquireTokenSilent(silentRequest).catch((e) => {
            if (e instanceof InteractionRequiredAuthError) {
                return pca.acquireTokenInteractive(tokenRequest);
            }
        });
    } else if (accounts.length > 1) {
        // Multiple accounts found. Prompt the user to select an account.
        accounts.forEach((account) => {
            console.log(account.username);
        });
        return Promise.reject('Multiple accounts found. Please select an account to use.');
    } else {
        // No account found. Use interactive authentication.
        return pca.acquireTokenInteractive(tokenRequest);
    }
};

Reproduction Steps

If we follow exactly what in this document we will still get the error https://learn.microsoft.com/en-us/entra/external-id/customers/tutorial-cli-app-node-sign-in-sign-out

Expected Behavior

No loop back error

Identity Provider

Entra ID (formerly Azure AD) / MSA

Browsers Affected (Select all that apply)

Chrome

Regression

No response

Source

External (Customer)

tramhongoc commented 4 months ago

I've had the same problem with msal-node for Electron app after successfully logging in. Please help us to check this bug.

Screenshot 2024-05-11 at 12 31 01