microsoft-authentication-library-for-js icon indicating copy to clipboard operation
microsoft-authentication-library-for-js copied to clipboard

msal-react and the PKCE auth flow are incompatible with AzureAD App Proxy

Open rayterrill opened this issue 3 years ago • 22 comments

Core Library

@azure/msal or msal

Wrapper Library

@azure/msal-react

Description

Work with the AzureAD App Proxy team to ensure the new PKCE/SPA flow works with AzureAD App Proxy. Currently these are not compatible because of the way App Proxy works and modifies authentication methods.

Source

External (Customer)

rayterrill avatar Apr 08 '21 17:04 rayterrill

@rayterrill Thanks for filing this issue. Can you please provide more details on what doesn't work? This is the first I'm hearing about incompatibility here.

cc: @hpsin

jasonnutter avatar Apr 08 '21 18:04 jasonnutter

Here’s what the Authentication tab in App Registrations looks like for my app prior to adding AzureAD App Proxy. Note that the only “Platform” I have configured is the “Single-page application” platform: image

Everything works great.

I go in and configure AzureAD App Proxy for my app, and Save it. image

If I go back to the App Registration view of my app, it looks like AzureAD App Proxy has added a new “Web” platform to my app: image

When I try to use the App Proxy (after setting up DNS), I get this error. This error occurs both internally (without hitting App Proxy) and externally (through App Proxy) because App Proxy has changed/added an auth method for my app. Note that at this point my app is broken both internally and externally. image

Confirmed this AM with the AzureAD App Proxy team via email that these are currently incompatible and there's no ETA for resolution (via Ronnie Greenstein and Jasmine Betthauser @ Microsoft).

You are indeed correct - AppProxy does not support apps using this new flow as it does not work with the way AppProxy is currently integrated with AAD.

Created a User Voice issue to request this be supported: https://feedback.azure.com/forums/169401-azure-active-directory/suggestions/43106385-support-pkce-spa-auth-flow-with-azuread-app-proxy

Let me know what else I can add.

rayterrill avatar Apr 08 '21 18:04 rayterrill

@jasonnutter I mostly wanted to add this as a note in case others run into this same scenario - this def took a while to track down what was happening.

rayterrill avatar Apr 08 '21 18:04 rayterrill

@rayterrill Great, thanks! I'll follow up internally and let you know if we can provide any additional guidance.

jasonnutter avatar Apr 08 '21 18:04 jasonnutter

Thank you! Working with the library has been great!

rayterrill avatar Apr 08 '21 18:04 rayterrill

Been trying to get msal-angular to work with AzureAD AppProxy for weeks now with no luck and the same error. Hopefully this fix will resolve our issue too.

bsrchalam avatar Apr 09 '21 15:04 bsrchalam

@bsrchalam That's exactly why I created this issue - banging my head against this and finally tracked it down. Was hoping to save others some time. ❤️

rayterrill avatar Apr 11 '21 17:04 rayterrill

@rayterrill was it clearing the response headers as well? especially access-control-allow-origin

bsrchalam avatar Apr 15 '21 21:04 bsrchalam

@bsrchalam I don't know - it basically entirely failed to load the front end with the sign-in error I included in the screenshot because it wasn't able to get past the initial AzureAD auth (which we require up-front before we display content).

rayterrill avatar Apr 16 '21 01:04 rayterrill

Me and a colleague have struggled a lot with this error. We have 2 identical apps, same code, just different key vaults. The latest app reg. works through an app proxy and the old one gets the error "AADSTS9002325: Proof Key for Code Exchange is required for cross-origin authorization code redemption". After we compared manifests and tried a lot, we gave up. We deleted the old app registration and created a new one and then we turned on the app proxy in the related enterprise application afterward, we have only single page redirects URIs added and now it works :) But we have no idea where the error was...

jesben avatar Apr 22 '21 12:04 jesben

I can't deploy modern frontends - such as Angular and React - that use MSAL 2.x to hardened tenants (where PKCE is a requirement).

From what I can see no progress has been made on this since it was reported. Can I get a handle on whether you intend to fix this or not, because I must replace our Azure AD Application Proxy infrastructure otherwise.

mattmelton avatar Nov 22 '21 11:11 mattmelton

Created a User Voice issue to request this be supported: https://feedback.azure.com/forums/169401-azure-active-directory/suggestions/43106385-support-pkce-spa-auth-flow-with-azuread-app-proxy

Website were moved, here is the new link: https://feedback.azure.com/d365community/idea/e8d41bf6-c625-ec11-b6e6-000d3a4f0789

SimonGolms avatar Jan 13 '22 12:01 SimonGolms

We are also in the progress to Azure App Proxy and due to the previous implementation of MSAL 2.x in our web applications, we are running into incompatibilities with Microsoft products. Who (MSAL or App Proxy team) is responsible for this? Who should be contacted to ensure that this incompatibility is resolved in a prioritized way or how can we support you @jasonnutter in solving this issue asap?

SimonGolms avatar Jan 13 '22 12:01 SimonGolms

@SimonGolms Apologies for the delayed response. The App Proxy team is aware of this issue, however, we have no ETA to share at this time, unfortunately. We'll update this issue when we have more information.

jasonnutter avatar Jan 13 '22 22:01 jasonnutter

@jasonnutter thanks for your quick reply, sounds great that you are aware of the issue and urgency! Looking forward to any progress and hopefully a fix to the issue soon. And please let me know if there is anything we can do to support you here.

SimonGolms avatar Jan 14 '22 06:01 SimonGolms

@rayterrill if I understand the Azure App proxy correctly, it sits between the user and the webserver where the app is hosted. If you set it to pre-authenticate, like you, the users’ browser first needs to login before the browser can even access the JavaScript files.

What happens if you would just open the login pop-up afterwards?

  1. User tries to access app
  2. App Proxy forces user to login
  3. User logged in
  4. Browser loads SPA
  5. SPA triggers login
  6. User already logged in pop-up closes automatically
  7. Both the app proxy and the spa are logged in.

svrooij avatar Apr 14 '22 20:04 svrooij

@svrooij I've moved on and no longer work with AzureAD - feel free to close. :)

rayterrill avatar Apr 14 '22 21:04 rayterrill

Any update here? I still have this issue in mid 2023 with Angular 14, MSAL 2.5.9

benwhitman avatar Jul 28 '23 09:07 benwhitman

@benwhitman I think my comment is still relevant, https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/3420#issuecomment-1099613801

But on the other hand I think this issue should just be closed, doing pkce using MSAL from a SPA, defeats the whole purpose of using the pre-authentication.

Why not do the following:

  • Protect your api with the proxy
  • Host your SPA on any unprotected or not pre-authenticated url and call MSAL from there. With the token you can then access the protected api.

With ADFS you could "split" one domain where only a specific folder (like /api) would be protected, that would also enable MSAL, if you would absolutely want to use that.

svrooij avatar Jul 29 '23 20:07 svrooij

Any update here? I still have this issue in mid 2023 with Angular 14, MSAL 2.5.9

@benwhitman Did you ever resolve this? I am in the same boat and wound up here. Angular 14 and MSAL 2.4.3

wesysec avatar Oct 19 '23 20:10 wesysec

@wesysec I found a workaround for this issue:

Configure your SPA to use a different path as the redirectUri, e.g. https://example-company.msappproxy.net/login.

Then add the base path https://example-company.msappproxy.net/ as the Web Redirect URI and https://example-company.msappproxy.net/login as the SPA redirect URI.

image

FabianSamuelssonSR avatar Oct 20 '23 06:10 FabianSamuelssonSR

@FabianSamuelssonSR We're struggling with the same isssue. I have tried your workaround but I'm getting an AADSTS500112 error, specifying that my reply (the SPA URI) address does not match the reply adress (Web URI) provided when requesting Authorization code.

Did you get the same error or do you have any suggestions on solving that?

Gurkeb avatar Dec 01 '23 14:12 Gurkeb