Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add the following dependency to your `pom.xml`:
<dependency>
<groupId>com.autodesk</groupId>
<artifactId>forge-java-sdk</artifactId>
<version>1.0.2</version>
<version>1.0.4</version>
</dependency>
```

Expand All @@ -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"
}
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name>forge-java-sdk</name>
<description>SDK of Autodesk Forge</description>
<url>https://github.com/Autodesk-Forge/forge-api-java-client</url>
<version>1.0.2</version>
<version>1.0.4</version>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/autodesk/client/auth/OAuth2TwoLegged.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public OAuth2TwoLegged(String clientId, String clientSecret, List<String> 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");
Expand Down Expand Up @@ -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
*/
Expand All @@ -205,11 +205,14 @@ public Credentials authenticate() throws Exception {
if (flow == OAuthFlow.application) {

final String url = this.tokenUrl;

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
headers.put("Accept", "application/json");
headers.put("Authorization", getAuthorizationString());

Map<String, String> 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()) {
Expand All @@ -218,7 +221,7 @@ public Credentials authenticate() throws Exception {

Credentials response = null;
try {
String bodyResponse = post(url, body, new HashMap<String, String>());
String bodyResponse = post(url, body, headers);
JSONObject jsonObject = null;

// get the access token from json
Expand Down Expand Up @@ -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()));
Expand Down