【发布时间】:2018-01-19 20:47:25
【问题描述】:
刚刚开始使用 Firebase 电话身份验证。看起来很漂亮,但是我遇到了一个错误。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "SESSION_EXPIRED"
}
],
"code": 400,
"message": "SESSION_EXPIRED"
}
}
从验证码开始:(标准文档代码!)
var applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
'size': 'invisible',
'callback': function(response) {
},
'expired-callback': function() {
}
});
它的渲染和验证码运行良好。
接下来是将验证码发送到手机的登录位。效果很好:
$scope.signInWithPhoneNumber = function signInWithPhoneNumber() {
var phoneNumber = "*censored*";
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, applicationVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
$scope.setConfirmationResult(confirmationResult);
alert('Result: ' + JSON.stringify(confirmationResult));
}).catch(function (error) {
// Error; SMS not sent
alert('Error: ' + error);
// ...
});
};
最后是验证用户从短信中输入的代码。这是我收到错误 400 的时候:
$scope.AuthenticateCode = function (code) {
var code = String(document.getElementById("auth_code").value);
var confirmationResult = $scope.getConfirmationResult();
alert(code);
confirmationResult.confirm(code).then(function (result) {
// User signed in successfully.
var user = result.user;
console.log('Signed In! ' + JSON.stringify(user));
// ...
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
// ...
});
}//end of AuthenticateCode
错误来自 VerifyPhone 方法: https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPhoneNumber?key=审查
有什么帮助或想法吗?
非常感谢, 基兰
【问题讨论】:
标签: firebase ionic-framework firebase-authentication