dotMorten / WinUIEx

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

Windows Maui app - WebAuthenticator for OIDC: activatedEventArgs.Kind is always Launch #176

Open rmaddu opened 3 days ago

rmaddu commented 3 days ago

Hi, To resolve a bug in the Windows App SDK for OIDC in my Windows Maui app (Could not find file ..AppxManifest.xml), we are trying to integrate the fix provided in https://dotmorten.github.io/WinUIEx/concepts/WebAuthenticator.html https://dotmorten.github.io/WinUIEx/concepts/Maui.html#use-winuiexs-webauthenticator-instead-of-net-mauis

I have written code in App.xaml.cs: - public partial class App : MauiWinUIApplication {
public App() { if (WinUIEx.WebAuthenticator.CheckOAuthRedirectionActivation()) return; this.InitializeComponent();
}

call is triggering to CheckOAuthRedirectionActivation and checking activatedEventArgs.Kind whether it is a Protocol or not? My case always coming as Launch and returning False.

Also I have written below lines in identity service- WebAuthenticatorResult authResult = await WinUIEx.WebAuthenticator.AuthenticateAsync(authUri, callbackuri);

I am gettng login page and able to enter credentials. But it is not returning. And in WebAuthenticator->Authenticate code, not getting the response from below line var uri = await tcs.Task.ConfigureAwait(false);

In manifest I have added -

$placeholder$

callbackuri is - {test://callback/}

Problem:

I am suspecting issue because of not getting the protocol kind, further call back is not registered initially, hence login page is not calling the call back function.

How to resolve this issue?

dotMorten commented 3 days ago

@rmaddu did you also make the required changes to the windows app manifest?

rmaddu commented 3 days ago

Yes. In ...\Platforms\Windows\Package.appxmanifest file I have added below lines. I didn't add any in ...\Platforms\Windows\app.manifest..

`

$placeholder$ `
rmaddu commented 3 days ago

Anything missing here. Why kind is Launch always and why login window is not calling the call back function?

Any help to resolve this?

dotMorten commented 3 days ago

Hard to know. There's not a lot of info or a reproducer. Did you try debug into winuiex and see why? Does the Maui sample app work for you?

rmaddu commented 3 days ago

1 2

sample snapshots added. Getting Launch always.

dotMorten commented 3 days ago

One place says "test" and the other "myscheme".

Did you try the sample app that's in this repo? If that works try and reconfigure the app to work with your service and try again. Without a full reproducer app from you there's not much else I can offer than guesswork. The samples are there for you too to help debug.

rmaddu commented 3 days ago

ok.

rmaddu commented 3 days ago

Which sample should I execute - WinUIExMauiSample or WinUIExSample?

rmaddu commented 1 day ago

Hi, I am able to debug the WinUIExSample. Workflow also success.

I have integrated the code to my application -

1

any missing things here -

rmaddu commented 1 day ago

Any help is appreciated...

dotMorten commented 1 day ago

Please provide a sample app that reproduces the problem. I can't guess what you're missing. However since the sample app is working you're probably just missing something in your app or a setting is wrong.

rmaddu commented 1 day ago

4 5 3**

Instead of using WinUiEx, copied the WebAuthenticator.cs to project. ** Do we need to copy this to any specific location in project or anywhere is fine? Do we need to copy any other files?

Also provide any links or threads so that I can cross check once again. As we have integrated the code in product, I can't share it.

do we need to update any in below -

6

rmaddu commented 1 day ago

Please let me know if any other information is required?

rmaddu commented 1 day ago

One observation: In WinUIEx sample: both redirect_uri and callbackUri is same. string callbackUri = "winuiex://"; string authorizeUri = $"{server.Url}?response_type={responseType}&client_id={clientId}&redirect_uri= {Uri.EscapeDataString(callbackUri)}&scope=photo+offline_access";

var result = await WebAuthenticator.AuthenticateAsync(new Uri(authorizeUri), new Uri(callbackUri), oauthCancellationSource.Token);

In my sample: both redirect uri and callbackUri are different. redirect_uri is HTTPS URL. string callbackUri = "hsi.nwm://callback/";
redirect_uri = https://XX.com/XXAuthenticatorService/signin-oidc

How to handle this situation?

Is it possible to use a custom protocol in the Package.appxmanifest?

rmaddu commented 22 hours ago

When I integrated my authurl (https://XX.com/XXAuthenticatorService/mobileauth/OpenIdConnect) in WinUIEx sample application, I am getting login page. After successful login, asking to switch to app. But app code is not hitting.

Seems redirecturi (i.e., HTTPS) and callbackuri ("winuiex://") are different, applications are not working.

Any help to resolve this?

rmaddu commented 6 hours ago

Any help is appreciated...

dotMorten commented 6 hours ago

The redirect url needs to use the same schema as what's in the app manifest and must be unique. You set that up in the service where you configure your app for oauth where you should also specify that schema.