Skip to content

Commit 8ed7fd6

Browse files
authored
updateAccessToken() throw new ClientHandlerException() if non HTTP 200 code or accessTokenResponse is null
There was no error indication in case the oAuth request get back a non HTTP 200 code, e.g. HTTP 400 / 401 / 403 / ....
1 parent 76b3a20 commit 8ed7fd6

File tree

1 file changed

+16
-3
lines changed
  • src/main/java/com/docusign/esign/client/auth

1 file changed

+16
-3
lines changed

src/main/java/com/docusign/esign/client/auth/OAuth.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.List;
44
import java.util.Map;
55

6+
import javax.ws.rs.core.Response;
7+
68
import org.apache.oltu.oauth2.client.HttpClient;
79
import org.apache.oltu.oauth2.client.OAuthClient;
810
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
@@ -84,17 +86,28 @@ public synchronized void updateAccessToken() {
8486
} catch (Exception e) {
8587
throw new ClientHandlerException(e.getMessage(), e);
8688
}
87-
if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) {
89+
if (accessTokenResponse != null)
90+
{
91+
// FIXME: This does not work in case of non HTTP 200 :-( oauthClient needs to return the plain HTTP resonse
92+
if (accessTokenResponse.getResponseCode() != Response.Status.OK.getStatusCode())
93+
{
94+
throw new ClientHandlerException("Error while requesting an access token, received HTTP code: " + accessTokenResponse.getResponseCode());
95+
}
96+
8897
if (accessTokenResponse.getAccessToken() == null) {
8998
throw new ClientHandlerException("Error while requesting an access token. No 'access_token' found.");
9099
}
91100
if (accessTokenResponse.getExpiresIn() == null) {
92101
throw new ClientHandlerException("Error while requesting an access token. No 'expires_in' found.");
93102
}
103+
94104
setAccessToken(accessTokenResponse.getAccessToken(), accessTokenResponse.getExpiresIn());
95-
if (accessTokenListener != null) {
96-
accessTokenListener.notify((BasicOAuthToken) accessTokenResponse.getOAuthToken());
105+
if (this.accessTokenListener != null) {
106+
this.accessTokenListener.notify((BasicOAuthToken)accessTokenResponse.getOAuthToken());
97107
}
108+
} else {
109+
// in case of HTTP error codes accessTokenResponse is null, thus no check of accessTokenResponse.getResponseCode() possible :-(
110+
throw new ClientHandlerException("Error while requesting an access token. No accessTokenResponse object recieved, maybe a non HTTP 200 received?");
98111
}
99112
}
100113

0 commit comments

Comments
 (0)