Opening and interacting with browser window in maui hybrid

blue kiwi 1 Reputation point
2022-07-26T18:16:43.037+00:00

I am trying to open a browser window for the purposes of using google authentication. Trying to use JS interop doesn't seem to work even though it should:

var userCredential = await client.SignInWithRedirectAsync(FirebaseProviderType.Google, async uri =>  
        {  
            string credential = "";  
              
            async Task OpenWindow()  
            {  
                await JSRuntime.InvokeAsync<string>("authURI", uri);  
            }  
  
            await OpenWindow();  
  
            //wait for redirect  
  
              
  
  
            return credential;  
        });  

function authURI(uri) {  
    var newWindow = window.open(uri);  
    console.log(newWindow);}  

So that doesnt work and prints null to console. I cant find the reference to that window I opened in the browser - probably that's why. Any idea for workaround/what am I doing wrong?
Is this a bug?

Developer technologies | .NET | Blazor
Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-07-26T21:53:35.24+00:00

    Maui hybrid app runs the Blazor code in a WebView, not a browser. You can not open a browser window from a WebView. Typically you would perform a custom naviagtion that the hosting app would catch and then the hosting app would create and display a new WebView and load the url.

    You would add this code in the Maui app that hosts the BlazorWebView.

    see the authentication docs suggestions on authentication:

    https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/security/?view=aspnetcore-6.0&pivots=maui

    note: I assume the Maui oauth provider already has code for this as the Msal library typically hosts a WebView


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.