maui: [Bug] Maui Essentials WebAuthenticator not working in WinUI
I’m attempting to use WebAuthenticator in Maui Essentials to authenticate a WinUI project, but it’s having an issue finding the manifest file. It throws an exception saying:
Could not find file ‘C:\WINDOWS\system32\AppxManifest.xml’.
If I add a local version of https://github.com/dotnet/maui/blob/main/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs into my project (I made PlatformAuthenticateAsync public to test it and just passed the url and callbackUrl in the WebAuthenticatorOptions) and adjust line 51 to:
var doc = XDocument.Load($"{AppDomain.CurrentDomain.BaseDirectory}AppxManifest.xml", LoadOptions.None);
It then finds the file, however, a new error is thrown that says:
System.Runtime.InteropServices.COMException: ‘There are no remote procedure calls active on this thread. (0x800706BD)’
Additionally, I set the CallbackUrl to:
new Uri("io.identitymodel.native://callback")
and the Url to:
new Uri("https://demo.identityserver.io")
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 27 (9 by maintainers)
@jayveedee I was able to fix that error by setting
Exported = truein the Activity class. You get this information if you see the build logs after setting it to more verbose from the VS settings.My final Activity was like this:-
Here’s one implementation that can probably be more or less lifted as is into MAUI: https://github.com/dotMorten/WinUIEx/blob/main/src/WinUIEx/WebAuthenticator.cs You might want to change the use of the module initializer and instead do it on app launch constructor
@davidbritch did you mean to close this with a doc pr?
@shv07 Mind opening an issue over in the WinUIEx repo and we can discuss there, but I’m guessing you’re adding a
Stateparameter to the authorize url? (there’s a fix incoming for that: https://github.com/dotMorten/WinUIEx/commit/e3118c4941ee25b8b76fdb6a44c1a5899fff9ccf)It appears that auth is not supported natively on WinUI 😦
Reproduce on windows with VS2022 17.2.0 Preview 2.0 [32215.517.main], attach repro sample 2702.zip.