node.js - Firebase Auth REST API:使用 Twitter 进行 OAuth 登录会出现错误 32“无法对您进行身份验证”
问题描述
我正在 Node.js 中编写一个函数,通过 REST API 使用 Twitter 凭据将用户登录到 Firebase(使用请求库发出请求)。我可以使用 Twitter 凭据发布推文,但尝试登录 Firebase/accounts:signInWithIdp
会返回以下错误:
{ error:
{ code: 400,
message: 'INVALID_IDP_RESPONSE : Failed to fetch resource from https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true, http status: 401, http response: {"errors":[{"code":32,"message":"Could not authenticate you."}]}',
errors: [ [Object] ] } }
这是我的代码:
loginWithOAuth = (idToken, postBody, onCompletion, onError) => {
var form = {
postBody: querystring.stringify(postBody),
requestUri: 'request uri',
returnIdpCredential: 'false',
returnSecureToken: 'true',
}
request.post({
url: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=' + firebase_api_key,
body: form,
json: true
}, (error, r, body) => {
// ...
});
}
postBody
形式在哪里
{
access_token: 'token',
oauth_token_secret: 'token secret',
providerId: 'twitter.com'
}
我的 Twitter 应用程序有权访问用户电子邮件。我还在requestUri
Firebase 和 Twitter 中加入了白名单。重新生成我的应用程序和用户密钥并没有什么不同。
我错过了什么?
解决方案
postBody
is not a stringified object, it is URL encoded:
var form = {
postBody: 'access_token=[TWITTER_ACCESS_TOKEN]&oauth_token_secret=[TWITTER_TOKEN_SECRET]&providerId=twitter.com',
requestUri: 'request uri',
returnIdpCredential: 'false',
returnSecureToken: 'true',
}
推荐阅读
- saml-2.0 - 如果未在服务集合中配置 .pfx 文件,则 Sustainsys.Saml2 注销不起作用
- c++ - 有没有一种巧妙的方法可以避免在 C++ 中使用嵌套类进行额外填充?
- firebase - 添加 firebase 插件会影响“flutter run”的行为方式吗?
- python - 基于掩码删除日期子字符串
- angular - Angular 材质多个项目拖放
- operation - 获取设置操作无法正常工作?
- r - 使用 shinny 删除 DT 包中的悬停选择
- c++ - C++ 数组转数字
- javascript - 无法解构“上下文”的属性“用户”,因为它未定义
- php - Laravel 用户被禁用的问题,仍然可以登录