简体   繁体   English

从请求中识别未经身份验证的 Cognito Identity ID

[英]Identify unauthenticated Cognito Identity ID from request

I have an AWS API, with access controlled by an IAM authoriser associated with the unauthenticated role of a Cognito Identity pool.我有一个 AWS API,其访问权限由与 Cognito Identity 池的未经身份验证角色关联的IAM 授权方控制。 A successful call to the API invokes a Lambda function.成功调用 API 会调用 Lambda function。

The current process is:目前的流程是:

  1. User obtains temporary security credentials .用户获得临时安全证书 This includes:这包括:
    • User IdentityId eg eu-west-2:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX .用户IdentityId例如eu-west-2:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX This is the information I require in my Lambda function - see below.这是我在 Lambda function 中需要的信息 - 见下文。
    • Access credentials: AccessKeyId , SecretKey and SessionToken访问凭证: AccessKeyIdSecretKeySessionToken
  2. The user calls the API using a signed request .用户使用签名请求调用 API。 The header of the request includes X-Amz-Security-Token , obtained from step 1请求的 header 包括X-Amz-Security-Token ,从步骤1获得
  3. If authorisation is successful, the request is sent on to the Lambda function. event.headers includes X-Amz-Security-Token如果授权成功,请求将发送到 Lambda function。 event.headers包括X-Amz-Security-Token

Is it possible for the Lambda function to identify the identity pool ID of the caller (eg eu-west-2:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX ), either from the data available in the header of the request, or any other means. Lambda eu-west-2:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX是否有可能从请求的 header 中可用的数据或任何其他方法。

Things I have tried:我尝试过的事情:

  • sts.getCallerIdentity with Invoke with caller credentials ticked in API Gateway sts.getCallerIdentity with Invoke with caller credentials在 API 网关中勾选
  • Looking at SessionToken , though this appears only to be a temporary access token rather than containing any useful data like a JWT.查看SessionToken ,虽然这似乎只是一个临时访问令牌,而不是包含任何有用的数据,如 JWT。

If absolutely necessary I can include the identity ID of the user with every request, but I'd prefer to avoid this if possible.如果绝对必要,我可以在每个请求中包含用户的身份 ID,但我希望尽可能避免这种情况。

The Cognito ID of the user is included in the requestContext property of the event object passed to your Lambda function.用户的 Cognito ID 包含在传递给您的 Lambda function 的event object 的requestContext属性中。

Eg the Identity of the Cognito user that access the API is:例如,访问 API 的 Cognito 用户的身份是:

event['requestContext']['identity']['cognitoIdentityId'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从未经身份验证的 Cognito 身份获取访问令牌 - How do I obtain an Access Token from an Unauthenticated Cognito Identity Mocking 用于前端单元测试的 AWS Cognito Identity 池提升错误:“没有为未经身份验证的访问提供 Cognito Identity 池” - Mocking AWS Cognito Identity pools for frontend unit tests to elevate error: "No Cognito Identity pool provided for unauthenticated access" Cognito Identity 的 CloudWatch 事件 - CloudWatch event for Cognito Identity 如何使用 Cognito 身份 ID 获取用户属性(用户名、email 等) - How to get user attributes (username, email, etc.) using cognito identity id amazon-cognito-identity-js 回调 - amazon-cognito-identity-js callbacks Cognito Identity Pools - 具有“动态”属性的基于属性的访问控制 - Cognito Identity Pools - Attribute-based access control with "dynamic" attributes 在 AWS Cognito 中将外部身份验证服务器配置为 OpenID Connect 身份提供商 - Configure external auth server as OpenID Connect identity provider in AWS Cognito 使用 amazon-cognito-identity.min.js 获取 Cognito 用户自定义属性 - Getting Cognito User custom attributes with amazon-cognito-identity.min.js AWS Cognito:在 Auth.signIn 中出现错误(验证 amazon-cognito-identity-js 已链接) - AWS Cognito: Getting error in Auth.signIn (Validate that amazon-cognito-identity-js has been linked) SAML IdP - AWS Cognito/IAM 作为身份提供商 - SAML IdP - AWS Cognito/IAM as an Identity Provider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM