AWS Cognito Identity JS:忘记/记住/不记得设备 [英] AWS Cognito Identity JS: Forget/Remember/Do Not Remember Device
问题描述
我正在使用AWS Cognito Identity JS SDK( https:// github .com / aws / amazon-cognito-identity-js ),而我试图设置一些按钮来测试 setDeviceStatusRemembered
, setDeviceStatusNotRemembered
和 forgetDevice
功能,但我不断收到错误消息:
I'm working with the AWS Cognito Identity JS SDK (https://github.com/aws/amazon-cognito-identity-js) and I'm trying to set up a few buttons to test the setDeviceStatusRemembered
, setDeviceStatusNotRemembered
, and forgetDevice
functionality but I keep getting an error saying:
MissingRequiredParameter:在参数中缺少必需的键'DeviceKey'
以下是其中一个功能的实现:
Here is an implementation of one of the functions:
forgetDevice = function(){
var cognitoUser = userPool.getCurrentUser();
if (cognitoUser != null) {
cognitoUser.getSession(function(err, session) {
if (err) {
alert(err);
signOut();
return;
}
console.log('session validity: ' + session.isValid());
cognitoUser.forgetDevice({
onSuccess: function (result) {
console.log('call result: ' + result);
},
onFailure: function(err) {
alert(err);
}
});
});
}
}
如果我更改如下功能:
forgetDevice = function(cognitoUser){
cognitoUser.forgetDevice({
onSuccess: function (result) {
console.log('call result: ' + result);
},
onFailure: function(err) {
alert(err);
}
});
}
然后我从 cognitoUser.authenticateUser调用该函数
成功
回调函数,将 cognitoUser
作为参数传递给 forgetDevice
函数在所有功能上都工作完美。
and I call the function from the cognitoUser.authenticateUser
success
callback function, passing cognitoUser
as argument into the forgetDevice
function above everything works perfectly.
从第一个对象中查看 session
对象实现,看来 session
对象不包含 DeviceKey
属性,因此 cognitoUser.forgetDevice ()
调用失败。
From looking at the session
object in the first implementation it appears that the session
object does not contain the DeviceKey
property so the cognitoUser.forgetDevice()
call fails.
我要弄清楚的是,我应该只调用 setDeviceStatusRemembered吗?
, setDeviceStatusNotRemembered
和 forgetDevice
函数在登录时有效,或者我应该能够调用它们在我的申请表中有任何时间?希望这是有道理的。任何帮助将不胜感激。谢谢!
What I'm trying to figure out is, should I just be calling the setDeviceStatusRemembered
, setDeviceStatusNotRemembered
, and forgetDevice
functions on login, or should I be able to call them any time within my application? Hopefully that makes sense. Any help would be greatly appreciated. Thanks!
推荐答案
此帮助吗?
请注意,如果设备使用要求用户选择加入的设置为用户池启用了跟踪,您需要实现onSuccess(result,userConfirmationNecessary)回调,收集用户输入并调用setDeviceStatusRemembered记住设备或setDeviceStatusNotRemembered记住设备。
Note that if device tracking is enabled for the user pool with a setting that user opt-in is required, you need to implement an onSuccess(result, userConfirmationNecessary) callback, collect user input and call either setDeviceStatusRemembered to remember the device or setDeviceStatusNotRemembered to not remember the device.
还可以尝试调用getCachedDeviceKeyAndPassword填充CognitoUser对象中的deviceKey吗?
Also can you attempt calling getCachedDeviceKeyAndPassword to populate the deviceKey in the CognitoUser object?
这篇关于AWS Cognito Identity JS:忘记/记住/不记得设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!