Skip to content

Commit 3780e50

Browse files
authored
RFC conform handling for grant_type=refresh_token without code
in case of grant_type=refresh_token there is no code
1 parent 76b3a20 commit 3780e50

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,25 @@ public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map
4949
code = value;
5050
} else if ("client_id".equals(key)) {
5151
clientId = value;
52-
} else if ("client_secret".equals(key)) {
53-
clientSecret = value;
54-
}
55-
}
56-
57-
if (grantType == null || code == null) {
58-
throw new OAuthSystemException("Missing grant_type/code");
59-
} else {
60-
body = "grant_type=" + grantType + "&code=" + code;
61-
}
62-
63-
if (clientId == null || clientSecret == null) {
52+
} else if ("client_secret".equals(key)) {
53+
clientSecret = value;
54+
}
55+
}
56+
57+
if (grantType == null) {
58+
throw new OAuthSystemException("Missing grant_type");
59+
}
60+
if (!grantType.equals(GrantType.REFRESH_TOKEN.toString()) && code == null) {
61+
throw new OAuthSystemException("Missing code for grant_type="+grantType);
62+
}
63+
64+
if (code == null) {
65+
body = "grant_type=" + grantType;
66+
} else {
67+
body = "grant_type=" + grantType + "&code=" + code;
68+
}
69+
70+
if (clientId == null || clientSecret == null) {
6471
throw new OAuthSystemException("Missing clientId/secret");
6572
} else {
6673
byte[] bytes = (clientId + ":" + clientSecret).getBytes();
@@ -113,4 +120,4 @@ public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map
113120
public void shutdown() {
114121
// Nothing to do here
115122
}
116-
}
123+
}

0 commit comments

Comments
 (0)