我们正在使用 API Gateway
公开我们位于 AWS Lambdas
前面的 API .作为授权人,Cognito
用户池已在 API Gateway 中用于对用户进行身份验证并保护 protected 端点。因此,一般流程是,用户传递下面提到的信息以通过 API 网关端点 ( /grantToken
) 从 cognito 获取访问 token :
1. App client id
2. App client secret
3. username
4. password
获取后
access_token
, 用户在访问 protected 端点时在 header 中传递此授权 token 。 Cognito 自动授权用户,并将请求重定向到特定的 AWS Lambda。这一切工作正常。我想知道的是,在 lambda 中,来自授权 token (在 header 中传递) - 如何确定传递了哪个用户的 token ?还有其他方法可以确定授权用户的身份吗? AWS Cognito 在这种情况下有什么用吗?
注意:如果我能得到
App client id
从传递的授权 token 中,它将满足我的目的。
最佳答案
回答您的问题:
1. 如何确定传递的是哪个用户的 token ?
例如:
var jwt = require('jsonwebtoken'); // you can use import
var decoded = jwt.verify(token, secret);
console.log(decoded) // bar
2、有没有其他方法可以确定授权用户的身份?
引用:https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_GetUser.html
3. 如果我可以从传递的授权 token 中获取 App 客户端 ID,它将满足我的目的。
引用: https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html#amazon-cognito-user-pools-using-the-access-token
正确做法:
此 URL 将帮助您找到应用程序客户端 ID:https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-client-apps.html
关于amazon-web-services - 从通过 Cognito 生成的授权 token 识别 AWS Lambda 中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57841114/