【问题标题】:AWS Cognito for standard token based authenticationAWS Cognito 用于基于标准令牌的身份验证
【发布时间】:2017-02-13 12:53:36
【问题描述】:

我已阅读此问题AWS Cognito for API token authentication,但我的问题是关于 AWS Cognito 于 2016 年 5 月推出的用户池功能。

所需用例:

我有一个 Node.js 后端和一个客户端 Web 应用程序 (Polymer),并且想使用 Cognito 来简化我的基于令牌的身份验证系统。

我想使用这个库进行用户身份验证,方法是让他们在客户端上注册和身份验证并存储 AWS 给我的访问令牌,然后对于所有未来对 Node.js 后端的请求,在标头中发送访问令牌.我希望后端可以使用 Cognito 检查访问令牌是否与有效会话相关联,如果是,则获取用户 ID。但是,我看不到这样的方法可以针对 Cognito 检查访问令牌。

有什么办法可以做到吗?

这是我在代码中设想的流程的一般概念:

// client
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        setCookie('access-token', result.getAccessToken().getJWT())
    },



// client
function fetchData() {
   ajax.request('/server/data',
   headers: {
    token: getCookie('access-token')
   })
}



// node server
get('/data', function(req, res) {
   AWSCognito.validateAccessToken(req.headers.token).then(function(userId)    {
    // if user id exists, this is a valid token. now have user id, can     look them up in database 
    // and do stuff
   }
})

【问题讨论】:

  • “有效会话”是否意味着您要检查用户当前是否在另一台设备上登录?还是您只是想验证用户是否就是他所说的那个人?

标签: node.js amazon-web-services amazon-cognito


【解决方案1】:

如果您想验证用户的身份,您只需在后端验证 Cognito 发出的 id 令牌即可。

【讨论】:

  • 我有一个使用 AdminInitiateAuth 的 Cognito 访问令牌服务器端,我将它存储在会话 cookie 中。我假设我需要在每个后续请求中验证该令牌。我是否需要针对每个请求调用 Cognito,还是可以在我的应用服务器端验证令牌?
猜你喜欢
  • 2016-04-11
  • 2022-01-15
  • 1970-01-01
  • 1970-01-01
  • 2021-01-25
  • 2016-01-23
  • 2016-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多