Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase ID令牌是否未经授权上载到Firebase/GCloud存储?_Firebase_Google Cloud Storage_Esp32 - Fatal编程技术网

Firebase ID令牌是否未经授权上载到Firebase/GCloud存储?

Firebase ID令牌是否未经授权上载到Firebase/GCloud存储?,firebase,google-cloud-storage,esp32,Firebase,Google Cloud Storage,Esp32,我使用ESP32将图像上传到Firebase存储,但是通过底层的Google云存储JSON API。所以,我正在使用进行身份验证,然后检索用于存储上载的ID令牌 但是,我在使用该ID令牌时遇到了一个未经授权的错误。但是,直接用来自的OAuth2.0令牌替换ID令牌,范围https://www.googleapis.com/auth/devstorage.read_write,工作正常;我可以在Firebase控制台中看到弹出的图像 我看到了,Doug提到了我试图获得的功能,但显然有一个bug 我

我使用ESP32将图像上传到Firebase存储,但是通过底层的Google云存储JSON API。所以,我正在使用进行身份验证,然后检索用于存储上载的ID令牌

但是,我在使用该ID令牌时遇到了一个未经授权的错误。但是,直接用来自的OAuth2.0令牌替换ID令牌,范围
https://www.googleapis.com/auth/devstorage.read_write
,工作正常;我可以在Firebase控制台中看到弹出的图像

我看到了,Doug提到了我试图获得的功能,但显然有一个bug

我的代码如下:

#包括“Arduino.h”
#包括“globalVars.h”
#包括“esp_camera.h”
#包括
#包括
void checkMotion()
{
延迟(10 000);
camera_fb_t*fb=esp_camera_fb_get();
uint8_t*fbBuf=fb->buf;
尺寸\u t fbLen=fb->len;
uint8_t*jpeg_buf=(uint8_t*)ps_malloc(fbLen);
frame2jpg(fb、2和jpeg_buf和fbLen);
长电流时间=毫秒();
HTTPClient-storageClient;
字符串存储\上传\路径=新\对象\基本\路径+字符串(currTime)+“.jpeg”;
开始(存储上传路径);
Serial.print(“上传到:”);
Serial.println(存储\上传\路径);
//使用来自Auth的ID标记--不起作用
Serial.println(idToken);//成功打印出来
字符串承载字符串=字符串(“承载”)+字符串(idToken);
addHeader(“授权”,bearerString);
//改为使用游乐场令牌,并对上面的内容进行评论——有效!
//addHeader(“授权”、“我的令牌在这里的持有人”);
//内容类型
addHeader(“内容类型”、“图像/jpeg”);
addHeader(“内容长度”,字符串(fbLen));
int uploadResponseCode=storageClient.POST(jpeg\u buf,fbLen);
串行打印(“响应代码:”);
Serial.println(字符串(uploadResponseCode));
String uploadResponseRaw=storageClient.getString();
Serial.println(“接收到的响应:+uploadResponseRaw”);
const size\u t responseCapacity=JSON\u OBJECT\u size(100);
静载响应;
反序列化错误deserializeResult=deserializeJson(dUploadResponse,uploadResponseRaw);
Serial.println(反序列化result.c_str());
storageClient.end();
免费(jpeg_buf);
}
使用idToken时,这是我收到的响应:

{
“错误”:{
“代码”:401,
“消息”:“无效凭据”,
“错误”:[
{
“消息”:“无效凭据”,
“域”:“全局”,
“原因”:“authError”,
“位置类型”:“标题”,
“位置”:“授权”
}
]
}
}
在测试期间,我甚至还修改了Firebase存储规则,以允许一切:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

我错过了什么?提前感谢。

Firebase ID令牌只能通过Firebase SDK使用。Firebase后端然后根据安全规则对ID令牌执行访问控制检查

通过GCP API访问云存储会绕过Firebase服务器和安全规则,因此不能使用Firebase ID令牌完成。您将不得不使用OAuth 2令牌