dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
572 stars 36 forks source link

HTTP 400 when using WebAuthenticator #144

Closed MarcinPawlicaFS closed 8 months ago

MarcinPawlicaFS commented 8 months ago

Hi, first of all - awesome library! However, when trying to use WebAuthenticator in Windows (because the native one still isn't fixed!), I am getting an HTTP 400 - BAD REQUEST error from Okta. I managed to narrow it down to the "state" json object in the query: image I noticed in your code, that you are transforming the initial "state" in the BrowserOptions url into an object by adding two properties to the original state, namely appInstanceId and signinId. Unfortunately, this causes Okta to return the above error. Do you know any way around that?

dotMorten commented 8 months ago

No idea why Okta doesn’t like that. It follows the spec of state parameters. Perhaps ask Okta why json in the state parameter isn’t supported ?

MarcinPawlicaFS commented 8 months ago

wow, that was a quick response :) Thanks, will do, was hoping this has happened somewhere else already

MarcinPawlicaFS commented 8 months ago

Hmm, according to Okta docs:

state - A value to be returned in the token. The client application can use it to remember the state of its interaction with the end user at the time of the authentication call. It can contain alphanumeric, comma, period, underscore, and hyphen characters.

Maybe urlencoding the curly brackets in the URL would help?

dotMorten commented 8 months ago

Just make sure you’re on the latest version of WinUIEx - there was a recent change to encoding of the url

dotMorten commented 8 months ago

Maybe urlencoding the curly brackets in the URL would help?

try it manually and see what happens

MarcinPawlicaFS commented 8 months ago

I am not, because for some reason I can't change the MicrosoftAppSdk version to 1.4x, so I'm on 2.1.0. That would explain a lot...

dotMorten commented 8 months ago

for some reason I can't change the MicrosoftAppSdk version to 1.4x

why not? If you’re using Maui see the doc: https://dotmorten.github.io/WinUIEx/concepts/Maui.html#include-winuiex-package-in-windows-target

MarcinPawlicaFS commented 8 months ago

Thank you, for some reason this didn't work for me initially, but now it did - managed to get 2.3.0 working. However, the curly brackets are not urlencoded. I tried urlencoding them manually, and it works, although the callback is not reaching my running app instance, but opening a new one instead... but this may be because it can't recognize the id due to the urlencoding. I'll have a look later to confirm.

MarcinPawlicaFS commented 8 months ago

OK, so I had to copy your code into a temp project of mine, but in the end replacing curly brackets with url codes did the trick with Okta: process.StartInfo.Arguments = $"url.dll,FileProtocolHandler \"{authorizeUri.ToString().Replace("\"", "%22").Replace("{", "%7B").Replace("}", "%7D")}\"";

dotMorten commented 8 months ago

Thanks for confirming. I'll have a look and see what we can do here

dotMorten commented 8 months ago

Fixed in v2.3.3