dotMorten / WinUIEx

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

MAUI - WebAuthenticator opening second instance of app rather than returning auth token #166

Closed leosimanonok closed 4 months ago

leosimanonok commented 4 months ago

In my MAUI app I've added

public App ()
{
    if (WinUIEx.WebAuthenticator.CheckOAuthRedirectionActivation())
        return;
    this.InitializeComponent();
}

to \Windows\App.xaml.cs, but the conditional is always returning true, so I end up with another instance of my app, rather than my access token.

I followed the instructions from https://dotmorten.github.io/WinUIEx/concepts/Maui.html

leosimanonok commented 4 months ago

You mentioned in similar issues that its probably a problem with the state parameter being passed to the custom uri, do you have an example of how it should look for the RedirectionCheck to work properly?

leosimanonok commented 4 months ago

Was my own fault not propagating the state parameter properly

483005 commented 1 month ago

@leosimanonok Can I ask you how did you solve this problem? I have exactly the same problem and cannot wrap my head around this. Your help would be greatly appreciated.

vukasinpetrovic commented 10 hours ago

@483005 When you start authentication process, "state" value is passed in the authorizeUri as a query parameter. It has to be returned back to callbackUri when auth is finished, as winUiEx library handles that state value and if it matches the one sent initially it will automatically close the new app instance (you won't even see it start as it happens instantly).

So if you are connecting to your auth api, make sure to read and pass back that state query parameter, or if you are using someone else auth (google, apple, etc.), they should do it automatically.