Search code examples
node.jsazureoauth-2.0azure-ad-msal

Azure msal ClientAuthError Help @azure/msal-node


I am trying to follow the tutorial for Microsoft active-directory

After inputting the client ID and secret into the code and running the code, it takes me to the login page where I login with the credentials but I get the following error:

"errorCode": "request_cannot_be_made",
"errorMessage": "Token request cannot be made without authorization code or refresh token.",
"subError": "",
"name": "ClientAuthError"

Does anybody know what is going on here?


Solution

  • The sample code works well: https://github.com/Azure-Samples/ms-identity-node/

    When using auth code flow, we need to get authorization code with getAuthCodeUrl() first, then obtain the access token with the authorization code by acquireTokenByCode(). You may miss getting authorization code, please check yours.

    Notes:

    1. Set Supported account types as "Accounts in any organizational directory and personal Microsoft accounts". If not, change 'common' in authority with your tenant-id.

    2. redirectUri in the sample code needs to be the same as Redirect URI in the portal.