我一直在努力让authy-client运行Firebase Cloud Functions,但我一直遇到ValidationFailedError。我一直在测试作者在https://www.npmjs.com/package/authy-client提供的例子,但没有运气。
对于我的Firebase功能,我一直在尝试这个:
const Client = require('authy-client').Client;
const client = new Client({ key: 'my API key here' });
exports.sendVerificationCode = functions.database.ref('users/{userId}/verify/status')
.onCreate(event => {
const sender = client.registerUser({
countryCode: 'US',
email: 'test@tester.com',
phone: '4035555555'
}).then( response => {
return response.user.id;
}).then( authyId => {
return client.requestSms({ authyId: authyId });
}).then( response => {
console.log(`SMS requested to ${response.cellphone}`);
throw Promise;
});
return Promise.all([sender]);
});
但是我收到了这个错误:
ValidationFailedError: Validation Failed
at validate (/user_code/node_modules/authy-client/dist/src/validator.js:74:11)
at _bluebird2.default.try (/user_code/node_modules/authy-client/dist/src/client.js:632:31)
at tryCatcher (/user_code/node_modules/authy-client/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.attempt.Promise.try (/user_code/node_modules/authy-client/node_modules/bluebird/js/release/method.js:39:29)
at Client.registerUser (/user_code/node_modules/authy-client/dist/src/client.js:617:34)
at exports.sendVerificationCode.functions.database.ref.onCreate.event (/user_code/index.js:24:25)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
at /var/tmp/worker/worker.js:695:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
我是Firebase云功能的新手,所以我可能会忽略一些显而易见的东西,但是从我读过的东西,然后()语句和函数本身需要返回/抛出一个Promise,所以我一起攻击它。
我还确保authy-client包含在package.json文件的依赖项中。
我最初报名参加了Twilio试用版,它为我提供了使用Authy创建应用程序的选项。需要确定的是,我还登录了Authy以检查API密钥是否相同,它们是否相同。所以我认为验证错误不是由API密钥引起的。
任何帮助将不胜感激。谢谢。
答案 0 :(得分:1)
谢谢大家的回答。我终于能够找到解决方案了。它与代码无关,exports.sendVerificationCode = functions.database.ref('users/{userId}/verify')
.onCreate(event => {
const status = event.data.child('status').val();
const phoneNum = event.data.child('phone').val();
const countryCode = event.data.child('countryCode').val();
var method;
if(status === 'pendingSMS')
method = 'sms';
else
method = 'call';
// send code to phone
const sender = authy.startPhoneVerification({ countryCode: countryCode, phone: phoneNum, via: method })
.then( response => {
return response;
}).catch( error => {
throw error;
});
return Promise.all([sender]);
});
是一个错误,但是当我在Firebase上设置结算时,DNS解析显然是一个问题。
至于我的最终代码,因为我原本想使用authy-client进行手机验证,它看起来像这样:
$config->define("configFile=s", {DEFAULT=>$dirname."/eversolar.ini"});
$config->args();
// Configfile must exist
-e $config->configFile or die "Configfile '", $config->configFile, "' not found\n";
// read configfile
$config->file($config->configFile);
pmu_log("Severity 3, Configfile is: " . $config->configFile . "\n");
// Look for secret file
$config->configFile($config->configFile.".secret");
if (-e $config->configFile) {
$config->file($config->configFile);
pmu_log("Severity 3, Configfile is: " . $config->configFile . "\n");
}
答案 1 :(得分:0)
/// <summary>
/// Returns the FieldInfo matching 'name' from either type 't' itself or its most-derived
/// base type (unlike 'System.Type.GetField'). Returns null if no match is found.
/// </summary>
public static FieldInfo GetPrivateField(this Type t, String name)
{
const BindingFlags bf = BindingFlags.Instance |
BindingFlags.NonPublic |
BindingFlags.DeclaredOnly;
FieldInfo fi;
while ((fi = t.GetField(name, bf)) == null && (t = t.BaseType) is Type)
;
return fi;
}
并不是什么意思。如果你想捕捉你的承诺序列中任何地方可能出现的问题,你应该有一个catch部分。一般形式是:
throw Promise
但是,这并不一定能解决你的错误。这可能来自您调用的API。
答案 2 :(得分:0)
Twilio开发者传道者在这里。
道格是关于throw Promise
的,这肯定需要改变。
然而,错误似乎是在此之前和API中出现的。具体来说,堆栈跟踪告诉我们:
at Client.registerUser (/user_code/node_modules/authy-client/dist/src/client.js:617:34)
所以问题出在registerUser
函数中。最好的办法是尝试暴露更多从API生成的错误。这应该会为您提供所需的信息。
这样的事情应该会有所帮助:
const Client = require('authy-client').Client;
const client = new Client({ key: 'my API key here' });
exports.sendVerificationCode = functions.database.ref('users/{userId}/verify/status')
.onCreate(event => {
const sender = client.registerUser({
countryCode: 'US',
email: 'test@tester.com',
phone: '4035555555'
}).then( response => {
return response.user.id;
}).then( authyId => {
return client.requestSms({ authyId: authyId });
}).then( response => {
console.log(`SMS requested to ${response.cellphone}`);
}).catch( error => {
console.error(error.code);
console.error(error.message);
throw error;
});
});
让我知道这是否有帮助。