正如标题所述,我想从本机 Java 桌面应用程序访问bitbucket API 。Bitbucket 要求应用程序使用 OAuth2,为此我发现Oltu应该可以完成这项工作。
但是,我对 OAuth 的了解非常有限,因此我还处于很早的阶段。这是我到目前为止所做的:
第 1 步:我使用我的 Bitbucket 帐户注册了一个 OAuth 消费者,并提供了以下详细信息:
Name: jerseytestapp
Description:
CallbackURL: http://localhost:8080/
URL:
问题一:我可以自动执行此步骤吗?
第 2 步:我运行了以下 Java 代码:
package jerseytest;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
public class BitbucketJersey {
public static void main(String[] args) {
OAuthClientRequest request;
try {
request = OAuthClientRequest
.authorizationLocation("https://bitbucket.org/site/oauth2/authorize")
.setClientId("jerseytestapp")
.setRedirectURI("http://localhost:8080")
.buildQueryMessage();
System.out.println(request.getLocationUri());
} catch (OAuthSystemException e) {
e.printStackTrace();
}
}
}
第 3 步:我收到以下 locationURI 并在 Firefox 中打开
https://bitbucket.org/site/oauth2/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A8080&client_id=jerseytestapp
问题 2:我需要使用浏览器还是可以从 Java 应用程序执行此操作?
我在 Firefox 中收到以下回复消息:
Invalid client_id
This integration is misconfigured. Contact the vendor for assistance.
问题 3:接下来正确的步骤是什么,我的方法有什么问题?