Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit a69c1fc

Browse files
committed
Add token revocation endpoint
1 parent 8bbebe5 commit a69c1fc

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/main/java/com/coinbase/api/Coinbase.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,17 @@ public String getAuthCode(OAuthCodeRequest request)
932932
*/
933933
public OAuthTokensResponse getTokens(String clientId, String clientSecret, String authCode, String redirectUri) throws UnauthorizedDeviceException, CoinbaseException, IOException;
934934

935+
/**
936+
* Revoke current access token.
937+
*
938+
* This client must have previously been initialized with an access token.
939+
* Future methods requiring authentication will fail.
940+
*
941+
* @throws CoinbaseException
942+
* @throws IOException
943+
*/
944+
public void revokeToken() throws CoinbaseException, IOException;
945+
935946
/**
936947
* Refresh OAuth tokens
937948
*

src/main/java/com/coinbase/api/CoinbaseImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.coinbase.api.entity.ReportsResponse;
6565
import com.coinbase.api.entity.Request;
6666
import com.coinbase.api.entity.Response;
67+
import com.coinbase.api.entity.RevokeTokenRequest;
6768
import com.coinbase.api.entity.Token;
6869
import com.coinbase.api.entity.TokenResponse;
6970
import com.coinbase.api.entity.Transaction;
@@ -1038,6 +1039,29 @@ public OAuthTokensResponse getTokens(String clientId, String clientSecret, Strin
10381039
return post(tokenUrl, request, OAuthTokensResponse.class);
10391040
}
10401041

1042+
@Override
1043+
public void revokeToken() throws CoinbaseException, IOException {
1044+
1045+
if (_accessToken == null) {
1046+
throw new CoinbaseException(
1047+
"This client must have been initialized with an access token in order to call revokeToken()"
1048+
);
1049+
}
1050+
1051+
URL revokeTokenUrl;
1052+
try {
1053+
revokeTokenUrl = new URL(_baseOAuthUrl, "revoke");
1054+
} catch (MalformedURLException ex) {
1055+
throw new AssertionError(ex);
1056+
}
1057+
1058+
RevokeTokenRequest request = new RevokeTokenRequest();
1059+
request.setToken(_accessToken);
1060+
1061+
post(revokeTokenUrl, request, Response.class);
1062+
_accessToken = null;
1063+
}
1064+
10411065
@Override
10421066
public OAuthTokensResponse refreshTokens(String clientId, String clientSecret, String refreshToken)
10431067
throws CoinbaseException, IOException {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.coinbase.api.entity;
2+
3+
import java.io.Serializable;
4+
5+
public class RevokeTokenRequest implements Serializable {
6+
private static final long serialVersionUID = -1445803678709058848L;
7+
8+
private String token;
9+
10+
public String getToken() {
11+
return token;
12+
}
13+
14+
public void setToken(String token) {
15+
this.token = token;
16+
}
17+
}

0 commit comments

Comments
 (0)