Skip to content

Commit df7e56f

Browse files
authored
Merge pull request #475 from seratch/issue-474
Fix #474 by making redirect_uri optional
2 parents 432fbab + 41a2e7e commit df7e56f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

slack-api-client/src/main/java/com/slack/api/methods/impl/MethodsClientImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,9 @@ public MpimOpenResponse mpimOpen(RequestConfigurator<MpimOpenRequest.MpimOpenReq
16801680
public OAuthAccessResponse oauthAccess(OAuthAccessRequest req) throws IOException, SlackApiException {
16811681
FormBody.Builder form = new FormBody.Builder();
16821682
form.add("code", req.getCode());
1683-
form.add("redirect_uri", req.getRedirectUri());
1683+
if (req.getRedirectUri() != null) {
1684+
form.add("redirect_uri", req.getRedirectUri());
1685+
}
16841686
form.add("single_channel", req.isSingleChannel() ? "1" : "0");
16851687
String authorizationHeader = Credentials.basic(req.getClientId(), req.getClientSecret());
16861688
return postFormWithAuthorizationHeaderAndParseResponse(form, endpointUrlPrefix + Methods.OAUTH_ACCESS, authorizationHeader, OAuthAccessResponse.class);
@@ -1695,7 +1697,9 @@ public OAuthAccessResponse oauthAccess(RequestConfigurator<OAuthAccessRequest.OA
16951697
public OAuthV2AccessResponse oauthV2Access(OAuthV2AccessRequest req) throws IOException, SlackApiException {
16961698
FormBody.Builder form = new FormBody.Builder();
16971699
form.add("code", req.getCode());
1698-
form.add("redirect_uri", req.getRedirectUri());
1700+
if (req.getRedirectUri() != null) {
1701+
form.add("redirect_uri", req.getRedirectUri());
1702+
}
16991703
String authorizationHeader = Credentials.basic(req.getClientId(), req.getClientSecret());
17001704
return postFormWithAuthorizationHeaderAndParseResponse(form, endpointUrlPrefix + Methods.OAUTH_V2_ACCESS, authorizationHeader, OAuthV2AccessResponse.class);
17011705
}

slack-api-client/src/test/java/test_locally/api/methods/OAuthTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public void test() throws Exception {
4141
.isOk(), is(true));
4242
}
4343

44+
@Test
45+
public void issue_474() throws Exception {
46+
assertThat(slack.methods(ValidToken).oauthAccess(r -> r.clientId("abc").clientSecret("xyz").code("xxx")).isOk(), is(true));
47+
assertThat(slack.methods(ValidToken).oauthToken(r -> r.clientId("abc").clientSecret("xyz").code("xxx")).isOk(), is(true));
48+
assertThat(slack.methods(ValidToken).oauthV2Access(r -> r.clientId("abc").clientSecret("xyz").code("xxx")).isOk(), is(true));
49+
}
50+
4451
@Test
4552
public void test_async() throws Exception {
4653
assertThat(slack.methodsAsync(ValidToken).oauthAccess(r ->

0 commit comments

Comments
 (0)