Receiving Invalid Grant Type Error Received From AWS Cognito When Supply Auth Code:如何获取 ID 和访问令牌以进行测试?

Receiving Invalid Grant Type Error Received From AWS Cognito When Supply Auth Code : How do I get Id and access tokens for testing?

当我提供授权码时,我无法从我的 AWS Cognito 用户池中成功获取 ID token/access 令牌。我写了一个 shell 脚本(见下文),并从服务器接收 invalid_grant 返回。

我已将使用 python 生成的 client_id:client_secret 的 base64 授权基本 header 编码为:

import base64

encode='my_client_id_string:my_client_secret_string'
base64.b64encode(encode)
#!/usr/bin/env sh

curl --location --request POST 'https://<domain>.auth.us-east-2.amazoncognito.com/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic <base64 encode string client_id:client_secret>' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'client_id=<client_id from app settings' \
--data-urlencode 'code=<code received from redirect url to my localhost app endpoint>' \
--data-urlencode 'redirect_uri=http://localhost:8000/my_redirect'

有什么想法吗?

解决了!

问题是由无效的客户端 ID 引起的。我为客户端 ID 值提供了一个拼写错误!