Share via

SPA app WITH nodejs backend auth code flow not supported?

Dean Hiller 0 Reputation points
Mar 26, 2025, 9:31 AM

We have an SPA with nodejs backend and I see loginRedirect() is for backend to get code and on backend get the access tokens on the server (PERFECT except the full page redirect using an SPA is bad).

We then move to loginPopup() but this gives all the tokens and we just want the auth code. Is there no method of doing SPA & nodejs with loginPopup auth code flow at all?

All examples are SPA no backend or nodejs in old app that does redirects taking the user away form the SPA(this is bad - don't want to load everything again).

closest post I found but not really same: https://learn.microsoft.com/en-us/answers/questions/2154027/can-spa-app-with-backend-exchange-the-auth-code-fo

Things to a turn for the worse. I thought ok, JWT is standard so I take the accessToken from the loginPopup and send to back end. My backend grabs the public signing key and verifies the accessotken and it FAILS. I cut/paste the accesstoken from the following code into jwt.io and it fails for them too!!!! Why are microsoft JWT's not JWTs?

const response = await this.msClient.loginPopup({
    scopes: ["openid", "profile", "User.Read", "api://biltup.com/BiltupLogin"],
});

console.log(`json response from microsoft=${JSON.stringify(response)}`);
console.log(`access token=${response.accessToken}`);


For example, here is an EXPIRED token of my test user that is NOT VALID on jwt.io while all google.com tokens and other providers are

accessToken -

eyJ0eXAiOiJKV1QiLCJub25jZSI6IjBrT2FRWkhrNHB4MHNDZ2ZhMFpaR3h2V1FBZU1pNllyZ293S0JSbzhIQm8iLCJhbGciOiJSUzI1NiIsIng1dCI6IkpETmFfNGk0cjdGZ2lnTDNzSElsSTN4Vi1JVSIsImtpZCI6IkpETmFfNGk0cjdGZ2lnTDNzSElsSTN4Vi1JVSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8yMmE2YjYxZS1jN2UwLTQzOTMtYmRmZS1jZTMxN2RiYzA5NjgvIiwiaWF0IjoxNzQzMDAwNDIwLCJuYmYiOjE3NDMwMDA0MjAsImV4cCI6MTc0MzAwNTI1OCwiYWNjdCI6MCwiYWNyIjoiMSIsImFjc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zRSQk5nZTNFUXptdnBzc1BXbzVWNlhrRjdpRHd3SVJPY09TdnZHcS01QSIsInRlbmFudF9yZWdpb25fc2NvcGUiOiJOQSIsInRpZCI6IjIyYTZiNjFlLWM3ZTAtNDM5My1iZGZlLWNlMzE3ZGJjMDk2OCIsInVuaXF1ZV9uYW1lIjoibGl2ZS5jb20jZGVhbkBiaWx0dXAuY29tIiwidXRpIjoiZG5QM1A1dnZHa0NVSHlWcWVwRXVBZyIsInZlciI6IjEuMCIsIndpZHMiOlsiNjJlOTAzOTQtNjlmNS00MjM3LTkxOTAtMDEyMTc3MTQ1ZTEwIiwiYjc5ZmJmNGQtM2VmOS00Njg5LTgxNDMtNzZiMTk0ZTg1NTA5Il0sInhtc19mdGQiOiIwNnZENEZObzhheEZvbmFRbXNLX1FVZ3NUOEoya3hkYWo3aFIzXy1qN3NBIiwieG1zX2lkcmVsIjoiMjQgMSIsInhtc19zdCI6eyJzdWIiOiItRFdSMlQyVU1wSG5IdzRjQTJzWWM4UzBKNVhaNVJQekRwMVUxTnNaYW04In0sInhtc190Y2R0IjoxNzQyNTQwMTU0fQ.Uk_5KTaaBGx_iW32N4SSxeTyJbfwXaFx43gfYHgg-7G7vge3uWf24MGTIFUFr0exslaa2qPGNS9K5fTZTYKBFzNRl2NUvZZU0EC7bHeeCrwd93aWtiZ_DGd-uGmObJGJjHelRw-R_qhrzjHeAIn224uJCHI-j8WsO4PYA0bhUUzNgrCmrRuYqHWfVZNkiK_CVSJQfbJVrB736GTHEkC9TZTcuTGDRBQuXgjb-dOpy8HgOyV2xBeJK-1AqeY6P4oUIArjVXCsEtk8Chc_FW0l-Y9KVOOQo6iVbMSHNWf9AXa_ih0hiZnpd9m3nXqj-y7IBFtXreUxLupIcXNcWTg-Rw

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
24,101 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.