首页 > 解决方案 > 如何从 Firebase 上的本机移动应用程序登录到 Web 应用程序

问题描述

我有一个使用 firebase auth 的网站。

我也使用 firebase auth sdk 开发原生移动应用程序(android、iOS 或 Unity)。

用户在移动应用程序上通过身份验证后,我将打开一个 web 视图,以便用户可以使用我的网站。如何使用他们在移动应用程序中提供的凭据让用户登录到 webview?

标签: androidfirebaseauthenticationwebviewfirebase-authentication

解决方案


如果您想在每个 webview 请求中发送授权令牌,您应该像这样覆盖 WebViewClient 中的 onReceivedHttpAuthRequest 方法。

webView.webViewClient = object : WebViewClient() {

    override fun onReceivedHttpAuthRequest(view: WebView?, handler: HttpAuthHandler?, host: String?, realm: String?) {
        handler?.proceed("token_auth", "authtoken_here")
    }

}

推荐阅读