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 NodeJS authentication error for WebApp and SPA

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
  • @azure/msal-node@1.0.0-alpha.0

Important: Please fill in your exact version number above, e.g. msal@1.1.3.

Framework

NodeJS - KoaJS

Description

I integrated msal-node with a NodeJS server following this example: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code/index.js

BTW, the app is NodeJS REST API server + ReactJS SPA served by the same server and I need to auth users with Azure AD only for calling my REST API, no need to call MS Graph API or similar, so should I use MSAL.js or there’s a better solution?

Error Message

If I register my app in Azure AD as Web app, I have an error of missing client_secret, otherwise if I register it as SPA I get AADSTS9002325: Proof Key for Code Exchange is required for cross-origin authorization code redemption.

Security

  • Is this issue security related?

Regression

  • Did this behavior work before? Version:

MSAL Configuration

// Provide configuration values here.
// For Azure B2C issues, please include your policies.

Reproduction steps

// Provide relevant code snippets here.
// For Azure B2C issues, please include your policies.

Expected behavior

Browsers/Environment

  • Chrome
  • Firefox
  • Edge
  • Safari
  • IE
  • Other (Please add browser name here)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jo-arroyocommented, Jul 13, 2020

@lucafaggianelli Thanks for bringing this to our attention. We are working on updating our node samples and will follow up.

0reactions
sangonzalcommented, Aug 21, 2020

@lucafaggianelli @riazXrazor @dvguo We now support auth code flow in web applications. Instead of creating a PublicClientApplication, you can create a ConfidentialClientApplication, and pass in the clientSecret or the clientCertificate into the configuration.

You can reference the auth code sample

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Sign in users in a Node.js & Express web app
Add app registration details; Add code for user login; Test the app. For more information, see the sample code that shows how to...
Read more >
API won't authenticate against AAD with token passed from ...
Until then, this topology isn't supported with v2 (hence MSAL JS). ... twice - once for your web app SPA, and another for...
Read more >
@azure/msal-node - npm
js MVC web application using OAuth 2.0 auth code with PKCE flow to acquire a token for a web API such as Microsoft...
Read more >
Microsoft Authentication Library for JavaScript (MSAL.js)
After our current libraries are up to standards, we will begin balancing new feature requests, with new platforms such as react and node.js...
Read more >
Simple Azure AD Authentication in a single page application ...
In turn, API Management will verify the token. If it does not pass the verification steps, a 401 error will be returned. We...
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