Skip to content

Commit bf977d8

Browse files
authored
Fix #967 Attach AppConfig#getSingleTeamToken() to App#client() (#970)
1 parent 890d794 commit bf977d8

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

bolt/src/main/java/com/slack/api/bolt/App.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public Slack getSlack() {
7676
* The default Web API client without any tokens.
7777
*/
7878
public MethodsClient getClient() {
79-
return config().getSlack().methods();
79+
// This token can be null if this app is not for a single workspace
80+
String token = config().getSingleTeamBotToken();
81+
return config().getSlack().methods(token);
8082
}
8183

8284
/**

bolt/src/test/java/test_locally/app/AppConfigTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.slack.api.bolt.request.builtin.EventRequest;
1111
import com.slack.api.bolt.request.builtin.SSLCheckRequest;
1212
import com.slack.api.bolt.response.Response;
13+
import com.slack.api.methods.response.auth.AuthTestResponse;
1314
import com.slack.api.model.event.ReactionAddedEvent;
1415
import lombok.extern.slf4j.Slf4j;
1516
import org.junit.After;
@@ -24,6 +25,9 @@
2425
import java.util.Map;
2526
import java.util.concurrent.atomic.AtomicBoolean;
2627

28+
import static org.hamcrest.CoreMatchers.is;
29+
import static org.hamcrest.CoreMatchers.nullValue;
30+
import static org.hamcrest.MatcherAssert.assertThat;
2731
import static org.junit.Assert.*;
2832

2933
@Slf4j
@@ -211,4 +215,32 @@ public void unmatchedHandler() throws Exception {
211215
assertEquals(400L, response.getStatusCode().longValue());
212216
}
213217

218+
@Test
219+
public void singleTeamBotTokenClient() throws Exception {
220+
App app = new App(AppConfig.builder()
221+
.signingSecret(secret)
222+
.singleTeamBotToken(AuthTestMockServer.ValidToken)
223+
.slack(slack)
224+
.build());
225+
226+
AuthTestResponse authTest = app.client().authTest(r -> r);
227+
assertThat(authTest.getError(), is(nullValue()));
228+
}
229+
230+
@Test
231+
public void authorizeClient() throws Exception {
232+
App app = new App(AppConfig.builder()
233+
.signingSecret(secret)
234+
.clientId("111.222")
235+
.clientSecret("secret")
236+
.slack(slack)
237+
.build());
238+
239+
AuthTestResponse authTest = app.client().authTest(r -> r);
240+
assertThat(authTest.getError(), is("invalid_auth_local"));
241+
242+
authTest = app.client().authTest(r -> r.token(AuthTestMockServer.ValidToken));
243+
assertThat(authTest.getError(), is(nullValue()));
244+
}
245+
214246
}

bolt/src/test/java/util/AuthTestMockServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AuthTestMockServer {
2626
"}";
2727
static String ng = "{\n" +
2828
" \"ok\": false,\n" +
29-
" \"error\": \"invalid\"\n" +
29+
" \"error\": \"invalid_auth_local\"\n" +
3030
"}";
3131

3232
@WebServlet

0 commit comments

Comments
 (0)