简体   繁体   English

在 MAUI Blazor hybrid 中与浏览器交互,以实现谷歌身份验证

[英]Interacting with browser in MAUI Blazor hybrid for the purpose of google autenthication

I am working on implementing a firebase authentication in a MAUI Blazor hybrid app.我正在努力在 MAUI Blazor 混合应用程序中实施 firebase 身份验证。

Using the web api wrapped in the popular FirebaseAutenthication.net library.使用包含在流行的 FirebaseAuthenthication.net 库中的 web api。

What I need to do is open a browser window with google consent screen and capture the url it redirects to.我需要做的是打开带有谷歌同意屏幕的浏览器 window 并捕获它重定向到的 url。

@inject NavigationManager navmanager;

        var client = new FirebaseAuthClient(config);

        var userCredential = await client.SignInWithRedirectAsync(FirebaseProviderType.Google, async uri =>
        {
            navmanager.NavigateTo(uri);


            //return credential
        });

This works fine but I am not sure how to interact with browser at all after it has been opened.这工作正常,但我不确定在打开浏览器后如何与浏览器交互。 Any tips please?请问有什么提示吗?

Edit: I think i'm going to try something with JS interop.编辑:我想我会尝试使用 JS 互操作。 There must be a way to capture redirect event.必须有一种方法来捕获重定向事件。

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所以这不起作用并将 null 打印到控制台

WebAuthenticator is a good choice to get the access token from the webpage. WebAuthenticator是从网页获取访问令牌的好选择。 The API consists mainly of a single method AuthenticateAsync which takes two parameters: The first uri should be used to start the web browser flow. API 主要由一个方法AuthenticateAsync组成,该方法接受两个参数:第一个 uri 应该用于启动 web 浏览器流程。 For the second uri, which you expect the flow to ultimately call back to can be able to be handleed because you have registered the firebase.对于第二个 uri,您希望流程最终回调到它可以得到处理,因为您已经注册了 firebase。 Here is the sample:这是示例:

var authResult = await WebAuthenticator.AuthenticateAsync(
        new Uri("https:"),
        new Uri("myapp://"));

var accessToken = authResult?.AccessToken;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 混合应用程序和谷歌分析/ firebase - hybrid app and google analytics/ firebase Firebase增强在Android应用中返回null - Firebase autenthication returns null in Android app 如何限制混合应用程序的 Google API 密钥? - How to restrict Google API Key for Hybrid app? 了解Firebase以及Google云功能的用途 - Understanding the Firebase and purpose of google cloud functions 我如何打开浏览器并监听 .NET MAUI 中的重定向? - How would I open a browser and listen for the redirect in .NET MAUI? google-services.json 中 other_platform_oauth_client 的用途是什么? - What's the purpose of other_platform_oauth_client in google-services.json? 使用 Google Analytics 跟踪混合(Flutter)应用程序:是否可以聚合 iOS 和 Android 统计数据? - Tracking of hybrid (Flutter) app with Google Analytics: Aggregation of iOS and Android stats possible? 谷歌的 Kindle 浏览器限制 firebase - Kindle browser limitations for google firebase Firebase和Ionic混合应用程序 - Firebase & Ionic hybrid App 我是否需要拥有Google Play帐户才能让Google在本地登录以进行测试? - Do I need to have Google Play Account to make google sign in locally for testing purpose in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM