[英]PCF App to App Oauth 2 grant_type = 'client_credentials' and scope uaa.resources. Local testing
[英]Oauth 2.0 with grant_type=client_credentials?
我正在尋找 Java 中的 OAuth 2.0 客戶端,它支持通過grant_type=client_credentials
進行機器對機器通信。 有什么建議嗎?
編輯:我在這里問,因為到目前為止 2 天的研究表明,有許多用於 OAuth 2.0 的庫,但似乎沒有一個支持所需的操作模式。
經過多次頭疼,我終於發現 ScribeJava 支持所需的操作模式——盡管它有些隱藏。
這是我采用的版本:
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
// Replace these with your client id and secret
final String clientId = "your client id";
final String clientSecret = "your client secret";
final OAuth20Service service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.defaultScope("any") // replace with desired scope
.build(new DefaultApi20() {
@Override
public String getAccessTokenEndpoint() {
return "http://127.0.0.1:8082/token";
}
@Override
protected String getAuthorizationBaseUrl() {
throw new UnsupportedOperationException(
"This API doesn't support a Base URL.");
}
});
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
final OAuth2AccessToken accessToken = service.getAccessTokenClientCredentialsGrant();
System.out.println("Got the Access Token!");
System.out.println(accessToken.getRawResponse());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.