Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/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
Google cloud firestore Firestore rest api在arduino ide中发出经过身份验证的请求_Google Cloud Firestore_Arduino_Firebase Authentication_Esp32 - Fatal编程技术网

Google cloud firestore Firestore rest api在arduino ide中发出经过身份验证的请求

Google cloud firestore Firestore rest api在arduino ide中发出经过身份验证的请求,google-cloud-firestore,arduino,firebase-authentication,esp32,Google Cloud Firestore,Arduino,Firebase Authentication,Esp32,我正在用esp32做一个物联网项目 webApi密钥在#define中硬编码。 我有这段代码用于auth部分 String url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + String(apiKey); http.setTimeout(2000); http.begin(url); http.addHeader("Content-Type&quo

我正在用esp32做一个物联网项目

webApi密钥在
#define
中硬编码。 我有这段代码用于auth部分

String url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + String(apiKey);
http.setTimeout(2000);
http.begin(url);
http.addHeader("Content-Type", "application/json");
String dataSent = "{\"email\":\"" + String(email) + "\",\"password\":\"" + String(pswd) + "\",\"returSecureToken\":\"true\"}";
// Issue the HTTP POST request.
int status = http.POST(dataSent);
Serial.println(status);
它返回200并解析响应,
idToken
存储在my
String token

当我尝试为firestore制作补丁时,它返回401

 String url = "https://firestore.googleapis.com/v1/projects/timer-test-soulx/databases/(default)/documents/devices/" + uniqueID + "?key=[" + apiKey + "]"; //working ok
http.setTimeout(1000);
http.begin(url);
http.addHeader("Authorization", "Bearer " + String(token)); //needs fixing
http.addHeader("Accept", "application/json");
http.addHeader("Content-Type", "application/json");
// Issue the HTTP POST request.
int status = http.PATCH(dataSent);
我的规则是
允许读、写:if request.auth!=无效


已经尝试更改规则以允许读取和写入,然后注释出授权标头,并且效果非常好。所以我认为问题很明显是授权头。我是否使用了错误的令牌?

这正是API身份验证应该如何完成的,因此这应该是可行的,您是否有其他帐户需要测试?也许这是您使用的特定帐户的问题。我有另一个帐户,请尝试使用该帐户。我还尝试了这个更改'http.addHeader(“Bearer”,token);'现在它返回403,我知道这是权限问题。奇怪的是,即使在修改规则以允许所有读写时,我也一直使用403。如果您使用403,可能firebase规则中存在错误配置,您可以共享相关firebase规则的整个片段吗?这意味着使用
匹配
部分和所有内容。@RafaelLemos我认为问题在于身份验证,我在这里提出了另一个问题:斜体粗体。简而言之,im-geting响应不是与postman发出的同一请求的完整响应(idToken不是完整长度,并且缺少expiration和refreshttoken),当我解析idToken时,问题会被带到firestore请求