我想了解使用令牌的Firebase自定义auth方法,但文档对我来说并不是那么清楚。之前,我试图与智威汤逊发电机玩,我想检查是否有使用的身份验证响应令牌通过JavaScript登录web客户端的方式:Firebase:通过REST获取令牌并使用signInWithCustomToken
1)首先,在击:
curl 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=[theapikey]' -H 'Content-Type: application/json' --data-binary '{"email":"[the-user-email]","password":"[the-user-valid-password]","returnSecureToken":true}'
2)响应:
{
"kind": "identitytoolkit#VerifyPasswordResponse",
"localId": "<theresponse-localid>",
"email": "<theresponse-user-email>",
"displayName": "<theresponse-displayname>",
"idToken": "<theresponse-idtoken-string>",
"registered": true,
"refreshToken": "<theresponse-refreshToken>",
"expiresIn": "3600"
}
3)因此,我的结果复制到一个JavaScript对象:
var token = {
"kind": "identitytoolkit#VerifyPasswordResponse",
"localId": "<localid-string>",
"email": "<user-email>",
"displayName": "<user-displayname>",
"idToken": "<idtoken-string>",
"registered": true,
"refreshToken": "<refreshtoken-string>",
"expiresIn": "3600"
};
4)我已经尝试了每一种尝试使用该令牌进行验证:
firebase.auth().signInWithCustomToken(token).catch(function(error) {
console.log("firebase.auth().signInWithCustomToken() Error: ");
console.log(error);
}
firebase.auth().signInWithCustomToken(JSON.stringify(token)).catch(function(error) {
console.log("firebase.auth().signInWithCustomToken() Error: ");
console.log(error);
}
firebase.auth().signInWithCustomToken(token.idToken).catch(function(error) {
console.log("firebase.auth().signInWithCustomToken() Error: ");
console.log(error);
}
5)对于每一个,我得到同样的错误:
"Object { code: "auth/invalid-custom-token", message: "The custom token format is incorrect", stack: "" }"
显然我错了,但大多数文档我阅读描述创建自定义JWT令牌。恐怕我还不明白。
什么是您的具体问题? –
我希望能够使用REST api来生成一个令牌,我可以在JavaScript中使用它来使用firebase.auth()来验证用户。signInWithCustomToken(令牌) – orellabac