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