此问题可能是由于在配置API Gateway Cognito Authorizer时出现了一些错误。以下是将此问题解决的步骤:
1.检查在API Gateway中的资源和方法URL是否正确配置,如下所示:
/your-resource-name/your-method-name
2.检查Cognito用户池的设置是否正确,如果已绑定到API Gateway,则应该可以正常使用。
3.确保在API Gateway Cognito Authorizer中设置了正确的Token源,即要么是访问令牌,要么是身份标识令牌。
4.请确保您的API Gateway Cognito Authorizer已设置为根据您的API Gateway方法执行授权检查。在API Gateway中选择您的方法,然后从菜单中选择“集成请求”>“授权”,然后确认选择了您的Cognito Authorizer。
以下是一个示例API Gateway Cognito Authorizer授权策略:
{ "Version": "2012-10-17", "Statement": [ { "Action": "execute-api:Invoke", "Effect": "Allow", "Resource": "arn:aws:execute-api:YOUR_REGION:YOUR_ACCOUNT_ID:YOUR_API_ID/YOUR_API_STAGE/YOUR_METHOD_NAME", "Condition": { "StringEquals": { "cognito:username": "${int-authUsername}" } } } ] }
如果仍然无法授权访问令牌,则可以尝试使用身份标识令牌来查看Cognito用户池中的设置是否正确。