invalid_client 在使用Java Spring后端请求Amazon Cognito令牌并使用代码时发生。

huangapple go评论66阅读模式
英文:

invalid_client when requesting Amazon Cognito token with code from java spring back end

问题

我在运行以下代码时遇到了{"error":"invalid_client"}错误:

    public static HttpResponse<String> getAuthToken(@NonNull final String redirectUri, @NonNull final String code) {
        return Unirest.post("https://<myUrl>/oauth2/token")
                .header("content-type", "application/x-www-form-urlencoded")
                .body("grant_type=authorization_code" +
                        "&client_id=" + CognitoConstants.COGNIITO_CLIENT_ID +
                        "&redirect_uri=" + redirectUri +
                        "&code=" + code)
                .asString();
    }

代码看起来是正确的,客户端 ID 也是正确的。

如果您知道从 Cognito 获取适当的令牌的更好方法,请告诉我。他们的文档对于 OAuth2 初学者来说并没有解释得很清楚。

谢谢 invalid_client 在使用Java Spring后端请求Amazon Cognito令牌并使用代码时发生。

英文:

I get {&quot;error&quot;:&quot;invalid_client&quot;} error when I'm running this:

    public static HttpResponse&lt;String&gt; getAuthToken(@NonNull final String redirectUri, @NonNull final String code) {
        return Unirest.post(&quot;https://&lt;myUrl&gt;/oauth2/token&quot;)
                .header(&quot;content-type&quot;, &quot;application/x-www-form-urlencoded&quot;)
                .body(&quot;grant_type=authorization_code&quot; +
                        &quot;&amp;client_id=&quot; + CognitoConstants.COGNIITO_CLIENT_ID +
                        &quot;&amp;redirect_uri=&quot; + redirectUri +
                        &quot;&amp;code=&quot; + code)
                .asString();
    }

the code seems to be correct, so as Client id.

Please, if you know a better way to Get a proper token from Cognito - tell me. Their documentation doesn't exactly explain anything for a noob in Oauth2

Thank you invalid_client 在使用Java Spring后端请求Amazon Cognito令牌并使用代码时发生。

答案1

得分: 0

已解决,需要在64位客户端:密钥中再添加一个编码后的标头。

英文:

Solved, needed to have another header with encoded in 64bit client:secret

huangapple
  • 本文由 发表于 2020年10月10日 01:56:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64285032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定