简体   繁体   English

未经授权的错误:Firebase function 从 android 应用调用

[英]UNAUTHENTICATED ERROR : Firebase function called from android app

I have just started working with callable functions on firebase. I deployed a function that gives the response hello world.我刚刚开始使用 firebase 上的可调用函数。我部署了一个 function 来响应 hello world。 It worked fine when I tested it locally.当我在本地测试时它工作正常。 Now I am trying to call it from android app.现在我正在尝试从 android 应用程序调用它。 According to this document , these callable functions automatically pass the authentication data and deserialise the data to get the user id in the function. When I run as suggested in the document above, I get an Unauthenticated error.根据此文档,这些可调用函数自动传递身份验证数据并反序列化数据以获取 function 中的用户 ID。当我按照上面文档中的建议运行时,出现未验证错误。 I have used google sign in using firebase auth in the app.我在应用程序中使用 firebase 身份验证使用谷歌登录。 I dont want to make it public and keep it private so only the users can send requests.我不想将其公开并保密,因此只有用户才能发送请求。 Is there any way I could manually include authentication in the header of the request.有什么办法可以在请求的 header 中手动包含身份验证。 Here is the code from the call这是通话中的代码

               sendmessage(string)
                        .addOnCompleteListener {
                            if (!it.isSuccessful){
                                val e= it.exception
                                if(e is FirebaseFunctionsException){
                                    val code =e.code
                                    val details = e.details
                                    Log.d("Firebase error",code.toString()+details.toString())
                                }
                          
                            }
                            else{
                                Log.d("result obtained",it.result.toString())
                            }
                        }
private fun sendmessage(question:String): Task<String> {
        val data = hashMapOf(
            "question" to question,
            "push" to true
        )

        return functions
            .getHttpsCallable("detectIntent")
            .call(data)
            .continueWith {
                val result=it.result?.data as String
                result
            }
    }


Callable functions don't provide any amount of control over what happens in the HTTP headers.可调用函数不提供对 HTTP 标头中发生的事情的任何控制。 Authentication is handled automatically, based on the state of the user signed in through Firebase Auth.基于通过 Firebase Auth 登录的用户的 state,自动处理身份验证。 If you're not getting an authenticated user in your function in context.auth , that means you made the request before sign-in was complete.如果您在 function 的context.auth中没有获得经过身份验证的用户,这意味着您在登录完成之前发出了请求。

暂无
暂无

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

相关问题 新创建的 Firebase 函数抛出 UNAUTHENTICATED 错误 - Newly Created Firebase Functions Throwing UNAUTHENTICATED Error 如何从 Android 应用程序中删除 Firebase 用户? - How to delete a Firebase user from Android App? 从 Firebase 问题中删除 android 应用程序 - Deleting android app from Firebase problem FirebaseError: permission-denied Firebase Functions / 如何在模拟器中允许未经身份验证的 function 调用 - FirebaseError: permission-denied Firebase Functions / How to allow unauthenticated function calls in emulator 从 Firebase 上传应用到 Google Play Android - Upload App From Firebase App Distribution to Google Play Android 升级到 Firebase JS 8.0.0:尝试导入错误:“app”未从“firebase/app”导出(导入为“firebase”) - Upgrade to Firebase JS 8.0.0: Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase') Android Firebase ChildEventListener 调用了两次 - Android Firebase ChildEventListener called twice 错误:需要使用事件参数调用云函数。 Firebase 控制台错误, - Error: Cloud function needs to be called with an event parameter. Firebase console error, 从 Angular Ionic 项目中的“@firebase/app”导入 { Firebase } 时出错 - Error with import { Firebase } from '@firebase/app' in Angular Ionic project Firebase Function 无法从源加载 function 定义错误解决方案 - Firebase Function Failed to load function definition from source error Solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM