【问题标题】:AWS Cognito Missing required key 'DeviceKey' in paramsAWS Cognito 在参数中缺少必需的密钥“DeviceKey”
【发布时间】:2019-07-31 20:37:26
【问题描述】:

您好,我正在使用非常有用的 Amazon Web 服务 Cognito 进行用户管理。

我会记住我的用户在登录时的设备,但是当我调用时

cognitoUser.setDeviceStatusRemembered()

我有这个错误信息:

参数中缺少必需的密钥“DeviceKey”

这就是我实现它的方式:

  AuthService.login($scope.username.toLowerCase(), $scope.password)
           .then(function(res) {
              if ($scope.rememberMe == true)
                AuthService.setRememberedDevice($scope.username);
            })

我的登录功能用了很长时间。

我已经阅读过这个问题: AWS Cognito Identity JS: Forget/Remember/Do Not Remember Device

...调用 getCachedDeviceKeyAndPassword() 可以解决这个问题,但我不知道在哪里可以找到该方法的实现或如何使用它。

我认为@Ionut Trestian 可以知道正确的答案

【问题讨论】:

    标签: javascript amazon-web-services amazon-cognito aws-cognito


    【解决方案1】:

    你在运行哪个环境?如果在浏览器中运行,令牌和设备密钥会存储在本地存储中,如果在服务器端环境中运行,它们会存储在内存中。

    【讨论】:

    • 感谢@Summer Guo 的回答,我都在做。我在开发中的 Firefox 浏览器和生产中的 Apache 服务器中运行,在这两种情况下,我都有相同的错误消息“参数中缺少必需的密钥 'DeviceKey'”。你知道怎么解决吗?
    【解决方案2】:

    我不确定您使用的是哪个 SDK/库。使用当前的 Amplify 库,您可以通过用户对象获取设备密钥:

    Auth.currentAuthenticatedUser({
    }).then(user => {
      user.getCachedDeviceKeyAndPassword(); // without this line, the deviceKey is null
      console.log(user.deviceKey);
    });
    

    【讨论】:

      猜你喜欢
      • 2016-12-05
      • 2020-05-21
      • 2017-04-28
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      相关资源
      最近更新 更多