auth0-blog / dotnet-maui-auth0-app

Apache License 2.0
17 stars 7 forks source link

Windows App won't launch browser... callback URL issue #10

Open blmiles opened 1 year ago

blmiles commented 1 year ago

Hello,

I have followed this code precisely. Maui app, targeting Android, iOS and Windows. All .Net7, latest OS on each.

This sets the callback:

        builder.Services.AddSingleton(new Auth0Client(new()
        {
            Domain = "mycompany.auth0.com",
            ClientId = "xxxxxxxxxxxxxxxxx",
            Scope = "openid profile email",
#if WINDOWS
            RedirectUri = "http://localhost/callback"
#else
      RedirectUri = "com.mycompany.mycompany://callback"
#endif
        }));

I keep getting this error:

One or more errors occurred. (You need to declare the windows.protocol usage of the protocol/scheme "http" in your AppxManifest.xml file)'

[External Code]
    mycompany.Auth0.WebBrowserAuthenticator.InvokeAsync(IdentityModel.OidcClient.Browser.BrowserOptions, System.Threading.CancellationToken) in WebBrowserAuthenticator.cs
    [External Code]
    mycompany.Auth0.Auth0Client.LoginAsync() in Auth0Client.cs
    mycompany.MainPage..ctor.AnonymousMethod__0() in MainPage.xaml.cs

Cannot find much on editing the AppxManifest.xml file and no access to it in VS either unless I'm missing something. Wonder if this might be a local Windows issue as I try run this on my local/dev machine.

EDIT: And in Android I get this:

One or more errors occurred. (You must subclass the WebAuthenticatorCallbackActivity and create an IntentFilter for it which matches your callbackUrl.)'

This sample I think needs to be expanded to include some of this info as there are obviously some new/additional steps missing. It is hard to keep up with the pace of change and moving technical targets, I realize that!

Thanks

feraguiba commented 1 year ago

Same issue when I tested on Android:

System.InvalidOperationException: You must subclass the WebAuthenticatorCallbackActivity and create an IntentFilter for it which matches your callbackUrl. at Microsoft.Maui.Authentication.WebAuthenticatorImplementation.AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) in D:\a_work\1\s\src\Essentials\src\WebAuthenticator\WebAuthenticator.android.cs:65 at MauiAuth0App.Auth0.WebBrowserAuthenticator.InvokeAsync(BrowserOptions options, CancellationToken cancellationToken) in /Users/faguirre/maui/examples/dotnet-maui-auth0-app/Auth0/WebBrowserAuthenticator.cs:12 at IdentityModel.OidcClient.AuthorizeClient.AuthorizeAsync(AuthorizeRequest request, CancellationToken cancellationToken) in //src/OidcClient/AuthorizeClient.cs:56 at IdentityModel.OidcClient.OidcClient.LoginAsync(LoginRequest request, CancellationToken cancellationToken) in //src/OidcClient/OidcClient.cs:75 at MauiAuth0App.Auth0.Auth0Client.LoginAsync() in /Users/faguirre/maui/examples/dotnet-maui-auth0-app/Auth0/Auth0Client.cs:37 at MauiAuth0App.MainPage.OnLoginClicked(Object sender, EventArgs e) in /Users/faguirre/maui/examples/dotnet-maui-auth0-app/MainPage.xaml.cs:34 at at System.Threading.Tasks.Task.<>c.b128_0(Object state) at Android.App.SyncContext.<>c__DisplayClass2_0.b0() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:36 at Java.Lang.Thread.RunnableImplementor.Run() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36 at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Java.Lang.IRunnable.cs:84 at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:22

feraguiba commented 1 year ago

Found this repository (same creator) that works in Android: https://github.com/auth0-blog/dotnet-maui-token-management