[英]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.