AWS lambda访问路径中的认知身份(通过api网关websocket api)

问题描述 投票:0回答:1

我正在创建一个websocket API网关,并且具有以下路线:

$ connect wich使用AWS_IAM授权(签名版本4)

$ disconnect

$ default

sendmessage

我遇到的问题如下,在连接lambda中,RequestContext.Identity具有所有有效的属性(类似于cognito身份ID的文件),但是当我通过websocket调用sendmessage时,RequestContext.Identity.SourceIp和RequestContext.Identity.UserAgent已填充,是否有任何方法可以在sendmessage路由中获取CognitoIdentityId?

$ connect RequestContext.Identity为

"CognitoIdentityPoolId": "eu-central-1:a520283f-1353-43d7-b441-b0fc5152b027",
"AccountId": "396151468972",
"CognitoIdentityId": "eu-central-1:1a9421b5-3361-4da9-8adf-22cf5d92eeb9",
"Caller": "AROAVYPDXWOWIJFD6FIYE:CognitoIdentityCredentials",
"ApiKey": null,
"SourceIp": "1.15.1.22",//modified
"CognitoAuthenticationType": "authenticated",
"CognitoAuthenticationProvider": "cognito-idp.eu-central-1.amazonaws.com/eu-central-1_gPSLBBoLn,cognito-idp.eu-central-1.amazonaws.com/eu-central-1_gPSLBBoLn:CognitoSignIn:7812ef00-44cd-4c3c-a8f7-df2434441e67",
"UserArn": "arn:aws:sts::396151468972:assumed-role/Cognito_NanoVoltsAuth_Role/CognitoIdentityCredentials",
"UserAgent": "BestHTTP 1.12.3",
"User": "AROAVYPDXWOWIJFD6FIYE:CognitoIdentityCredentials"

sendmessage RequestContext.Identity为

"CognitoIdentityPoolId": null,
"AccountId": null,
"CognitoIdentityId": null,
"Caller": null,
"ApiKey": null,
"SourceIp": "1.15.1.22",//modified
"CognitoAuthenticationType": null,
"CognitoAuthenticationProvider": null,
"UserArn": null,
"UserAgent": "BestHTTP 1.12.3",
"User": null
c# amazon-web-services aws-lambda aws-api-gateway amazon-cognito
1个回答
0
投票
您如何设法在第一个连接请求中传递信息?尽管有AWS_IAM身份验证,但在我的情况下仍为我创建了一个Web套接字,但没有授权信息。由于授权仅发生在连接阶段,因此可能丢失第二个呼叫标识信息。 https://medium.com/@lancers/using-custom-authorizer-for-websocket-apis-on-api-gateway-95abb517acab
© www.soinside.com 2019 - 2024. All rights reserved.