Skip to content

Commit baa2094

Browse files
authored
Merge pull request #61 from psytester/patch-5
check and set refresh_token in body of request
2 parents 3f1248a + f619c51 commit baa2094

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map
4040
builder = builder.header(key, headers.get(key));
4141
}
4242

43-
String grantType = null, code = null, clientId = null, clientSecret = null;
43+
String grantType = null, code = null, clientId = null, clientSecret = null, refreshToken = null;
4444
for (String entry : body.split("&")) {
4545
String key = entry.split("=")[0];
4646
String value = entry.split("=")[1];
@@ -52,6 +52,8 @@ public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map
5252
clientId = value;
5353
} else if ("client_secret".equals(key)) {
5454
clientSecret = value;
55+
} else if ("refresh_token".equals(key)) {
56+
refreshToken = value;
5557
}
5658
}
5759

@@ -61,11 +63,16 @@ public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map
6163
if (!grantType.equals(GrantType.REFRESH_TOKEN.toString()) && code == null) {
6264
throw new OAuthSystemException("Missing code for grant_type="+grantType);
6365
}
66+
if (grantType.equals(GrantType.REFRESH_TOKEN.toString()) && refreshToken == null) {
67+
throw new OAuthSystemException("Missing refresh_token for grant_type="+grantType);
68+
}
6469

65-
if (code == null) {
66-
body = "grant_type=" + grantType;
67-
} else {
68-
body = "grant_type=" + grantType + "&code=" + code;
70+
body = "grant_type=" + grantType;
71+
if (code != null) {
72+
body = body + "&code=" + code;
73+
}
74+
if (refreshToken != null) {
75+
body = body + "&refresh_token=" + refreshToken;
6976
}
7077

7178
if (clientId == null || clientSecret == null) {

0 commit comments

Comments
 (0)