Microsoft Graph, Node.js, Failed sign on using acquireTokenByUsernamePassword

Isaac 0 Reputation points
2023-07-17T03:53:09.6266667+00:00

I would like support troubleshooting a sign on error. For background, I am building an application that accesses data stored on SharePoint. I am experiencing an issue generating the necessary auth token using Node.js. As I am in development, I want acquire a token using Username and Password.

I repurposed the code here: https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-desktop-acquire-token-username-password?tabs=nodejs

Using Python, I was successful. However using Node.js I received the below error.

Note: I am certain that the username and password were the same in both Python and Node.

ServerError: invalid_grant: 50126 - [2023-07-17 03:39:10Z]: AADSTS50126: Error validating credentials due to invalid username or password.
Trace ID: 94e3ad62-7ce3-4556-b8bf-d0cb5b1e2800
Correlation ID: 0f26b304-73ce-4626-bbb4-1ed38a8c51b8
Timestamp: 2023-07-17 03:39:10Z - Correlation ID: 0f26b304-73ce-4626-bbb4-1ed38a8c51b8 - Trace ID: 94e3ad62-7ce3-4556-b8bf-d0cb5b1e2800
    at ServerError.AuthError [as constructor] (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:499:24)
    at new ServerError (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:3398:28)
    at ResponseHandler.validateTokenResponse (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:5429:19)
    at UsernamePasswordClient.<anonymous> (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:7231:41)
    at step (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:79:23)
    at Object.next (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:60:53)
    at fulfilled (C:\Projects\TerrComm\tp-scheduler\node_modules\@azure\msal-node\node_modules\@azure\msal-common\dist\index.cjs.js:50:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errorCode: 'invalid_grant',
  errorMessage: '50126 - [2023-07-17 03:39:10Z]: AADSTS50126: Error validating credentials due to invalid username or password.\r\n' +
    'Trace ID: 94e3ad62-7ce3-4556-b8bf-d0cb5b1e2800\r\n' +
    'Correlation ID: 0f26b304-73ce-4626-bbb4-1ed38a8c51b8\r\n' +
    'Timestamp: 2023-07-17 03:39:10Z - Correlation ID: 0f26b304-73ce-4626-bbb4-1ed38a8c51b8 - Trace ID: 94e3ad62-7ce3-4556-b8bf-d0cb5b1e2800',
  subError: ''
}
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,449 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 40,311 Reputation points
    2023-07-17T09:37:11.0466667+00:00

    Hi @Isaac

    The ROPC flow will have some constraints on username/password, please check it.

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.