【问题标题】:Token request on Exact Online not returning access tokenExact Online 上的令牌请求未返回访问令牌
【发布时间】:2016-02-22 17:21:58
【问题描述】:

我一直在尝试使用 OAuth 2.0 连接到 Exact Online。我们倾向于专注于 Java 应用程序,遗憾的是 Exact 没有 Java 的文档/示例/支持。

我能够进行身份验证请求,但是对于令牌请求,我遇到了一些麻烦。我的代码:

OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        code = oar.getCode();

        OAuthClientRequest oAuthRequest;
        try {
            oAuthRequest = OAuthClientRequest
                    .tokenLocation("https://start.exactonline.be/api/oauth2/token")
                    .setGrantType(GrantType.AUTHORIZATION_CODE)
                    .setClientId(CLIENT_ID)
                    .setClientSecret(CLIENT_SECRET)
                    .setRedirectURI(REDIRECT_URI)
                    .setCode(code)
                    .buildQueryMessage();


            OAuthClient client = new OAuthClient(new URLConnectionClient());

            OAuthJSONAccessTokenResponse oauthResponse = client.accessToken(oAuthRequest, OAuth.HttpMethod.POST);
        }

我环顾四周,但我找到的所有答案都没有解决问题。

  • 尝试使用其他令牌响应类型。
  • 尝试使用 .buildBodyMessage 而不是 .buildQueryMessage

我总是得到其中 1 个 ProblemExceptions:

Token request failed: unsupported_response_type, Invalid response! Response body is not application/json encoded

Token request failed: invalid_request, Missing parameters: access_token

我希望任何人都具有处理精确在线问题的经验,感谢任何帮助。

【问题讨论】:

标签: java oauth oauth-2.0 oltu exact-online


【解决方案1】:

不确定 Java 库是如何工作的,我只在 C# 上使用过 Exact Online。

问题似乎是库试图从 JSON 响应中提取 access_token,但响应中没有 JSON。您可能尚未授权您的应用程序(用户操作),或者您使用了错误的返回 URL 值(Exact 检查服务器端)。如果可能,您可能想查看实际输出(我猜是 HTML)。真正的例外应该在那里。

【讨论】:

    【解决方案2】:

    解决方案是使用旧版本的 Oltu 库。使用 0.31 有效,但 1.0.1 无效。奇怪的行为,但也许这会在未来对某人有所帮助。

    【讨论】:

      【解决方案3】:
       .tokenLocation("https://start.exactonline.be/api/oauth2/token")
                      .setGrantType(GrantType.AUTHORIZATION_CODE)
                      .setClientId(CLIENT_ID)
                      .setClientSecret(CLIENT_SECRET)
                      .setRedirectURI(REDIRECT_URI)
                      .setCode(code)
                      .buildBodyMessage();
      

      .buildQueryMessage() 更改为.buildBodyMessage() 时,它对我有用。

      这是最新的依赖:

          <dependency>
              <groupId>org.apache.oltu.oauth2</groupId>
              <artifactId>org.apache.oltu.oauth2.client</artifactId>
              <version>1.0.2</version>
          </dependency>
      

      【讨论】:

        猜你喜欢
        • 2013-08-10
        • 2016-10-19
        • 1970-01-01
        • 1970-01-01
        • 2013-12-01
        • 2021-11-21
        • 1970-01-01
        • 2011-10-25
        • 2016-01-05
        相关资源
        最近更新 更多