Skip to content
Merged
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
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.mymetaverse</groupId>
<artifactId>metaapi</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<build>
<defaultGoal>package install</defaultGoal>
<finalName>${project.name}-${project.version}</finalName>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.mymetaverse</groupId>
<artifactId>metaapi</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/mymetavese/metaapi/requests/token/OAuthToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import okhttp3.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

public class OAuthToken implements TokenHandler {
Expand All @@ -17,13 +18,16 @@ public class OAuthToken implements TokenHandler {

private final String clientId;
private final String clientSecret;
private final String[] oAuthScopes;

private final String baseAuthUrl;

private OAuthToken(final String clientId, final String clientSecret, final String baseAuthUrl) {

this.clientId = clientId;
this.clientSecret = clientSecret;
this.baseAuthUrl = baseAuthUrl;
this.oAuthScopes = new String[] {"wallet.read", "p2e.read", "p2e.add", "linkinglink.create", "linkinglink.read", "linkinglink.implicit"};

this.httpClient = new OkHttpClient();
this.gson = new Gson();
Expand Down Expand Up @@ -55,15 +59,20 @@ private void requestToken(boolean withCredentials) {
final FormBody.Builder formBody = new FormBody.Builder();

if (withCredentials) {

formBody.add("grant_type", "client_credentials");
formBody.add("client_id", this.clientId);
formBody.add("client_secret", this.clientSecret);
formBody.add("scope", this.getOAuthScopesAsString());

} else {

if (this.refreshToken == null)
throw new NullPointerException("Refresh token is not available, try first with credentials.");

formBody.add("grant_type", "refresh_token");
formBody.add("refresh_token", this.refreshToken);

}

builder.url(urlBuilder.build());
Expand Down Expand Up @@ -106,6 +115,19 @@ public String getToken() {
return accessToken;
}

public String getOAuthScopesAsString() {

StringBuilder oAuthScopesStringBuilder = new StringBuilder();

Arrays.stream(this.oAuthScopes).forEach(scope -> {
oAuthScopesStringBuilder.append(scope);
oAuthScopesStringBuilder.append(" ");
});

return oAuthScopesStringBuilder.toString();

}

@Override
public void reauthenticate() {
this.requestToken(true);
Expand Down