diff --git a/README.md b/README.md
index f3dba45..5f9009d 100755
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Add the following dependency to your `pom.xml`:
com.autodesk
forge-java-sdk
- 1.0.2
+ 1.0.4
```
@@ -44,7 +44,7 @@ repositories {
mavenLocal()
}
dependencies {
- compile "com.autodesk:com-autodesk-client:1.0.2"
+ compile "com.autodesk:com-autodesk-client:1.0.4"
}
```
diff --git a/pom.xml b/pom.xml
index f97a93a..9fb59f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
forge-java-sdk
SDK of Autodesk Forge
https://github.com/Autodesk-Forge/forge-api-java-client
- 1.0.2
+ 1.0.4
2.2.0
diff --git a/src/main/java/com/autodesk/client/auth/OAuth2TwoLegged.java b/src/main/java/com/autodesk/client/auth/OAuth2TwoLegged.java
index dbcd180..0c25a48 100644
--- a/src/main/java/com/autodesk/client/auth/OAuth2TwoLegged.java
+++ b/src/main/java/com/autodesk/client/auth/OAuth2TwoLegged.java
@@ -151,7 +151,7 @@ public OAuth2TwoLegged(String clientId, String clientSecret, List select
this.name = "oauth2_application";
this.type = "oauth2";
- this.tokenUrl = Configuration.getDefaultApiClient().getBasePath() + "/authentication/v1/authenticate";
+ this.tokenUrl = Configuration.getDefaultApiClient().getBasePath() + "/authentication/v2/token";
this.scopes.add("data:read");
this.scopes.add("data:write");
this.scopes.add("data:create");
@@ -196,7 +196,7 @@ public Boolean isAutoRefresh() {
}
/**
- * Get the access token in a 2-legged flow
+ * Get the access token in a 2-legged flow (updated to v2)
*
* @return
*/
@@ -205,11 +205,14 @@ public Credentials authenticate() throws Exception {
if (flow == OAuthFlow.application) {
final String url = this.tokenUrl;
+
+ Map headers = new HashMap<>();
+ headers.put("Content-Type", "application/x-www-form-urlencoded");
+ headers.put("Accept", "application/json");
+ headers.put("Authorization", getAuthorizationString());
Map body = new HashMap<>();
body.put("grant_type", "client_credentials");
- body.put("client_id", this.clientId);
- body.put("client_secret", this.clientSecret);
String scopeStr = getScopes();
if (!scopeStr.isEmpty()) {
@@ -218,7 +221,7 @@ public Credentials authenticate() throws Exception {
Credentials response = null;
try {
- String bodyResponse = post(url, body, new HashMap());
+ String bodyResponse = post(url, body, headers);
JSONObject jsonObject = null;
// get the access token from json
@@ -261,6 +264,11 @@ public void run() {
throw new Exception("getAccessToken requires application flow type");
}
}
+
+ private String getAuthorizationString() {
+ String encodedClientIdSecret = Base64.getEncoder().encodeToString((this.clientId + ":" + this.clientSecret).getBytes());
+ return "Basic " + encodedClientIdSecret;
+ }
public Boolean isAccessTokenExpired() {
return (this.credentials != null) && (this.credentials.getExpiresAt() <= (new Date().getTime()));