Skip to content

Commit f6a31a7

Browse files
authored
Fix #887 by skipping to create team_id cache data for metrics (#888)
1 parent 27ef15d commit f6a31a7

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

bolt-servlet/src/test/java/samples/OpenIDConnectSample.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public static void main(String[] args) throws Exception {
4949
OpenIDConnectUserInfoResponse userInfo = teamIdWiredClient.openIDConnectUserInfo(r -> r
5050
.token(refreshedToken.getAccessToken()));
5151
logger.info("userInfo: {}", userInfo);
52+
53+
// To revoke this, you can use auth.revoke API method
54+
// Slack.getInstance().methods().authRevoke(r -> r.token(refreshedToken.getAccessToken()));
55+
5256
} else {
5357
OpenIDConnectUserInfoResponse userInfo = client.openIDConnectUserInfo(r -> r
5458
.token(token.getAccessToken()));

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.Map;
1414
import java.util.concurrent.*;
1515

16+
import static com.slack.api.methods.impl.TeamIdCache.METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION;
17+
1618
@Slf4j
1719
public class AsyncRateLimitExecutor {
1820

@@ -60,7 +62,9 @@ public <T extends SlackApiResponse> CompletableFuture<T> execute(
6062
Map<String, String> params,
6163
AsyncExecutionSupplier<T> methodsSupplier) {
6264
String token = params.get("token");
63-
final String teamId = token != null ? teamIdCache.lookupOrResolve(token) : null;
65+
final String teamId = (token != null
66+
&& !METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION.contains(methodName)) ?
67+
teamIdCache.lookupOrResolve(token) : null;
6468
final ExecutorService executorService = teamId != null ? ThreadPools.getOrCreate(config, teamId) : ThreadPools.getDefault(config);
6569
return CompletableFuture.supplyAsync(() -> {
6670
if (NO_TOKEN_METHOD_NAMES.contains(methodName) || teamId == null) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219

220220
import static com.slack.api.methods.RequestFormBuilder.toForm;
221221
import static com.slack.api.methods.RequestFormBuilder.toMultipartBody;
222+
import static com.slack.api.methods.impl.TeamIdCache.METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION;
222223

223224
@Slf4j
224225
public class MethodsClientImpl implements MethodsClient {
@@ -3022,7 +3023,8 @@ protected Response postFormWithToken(
30223023
String methodName,
30233024
String token) throws IOException {
30243025
String teamId = this.teamId.orElse(null);
3025-
if (statsEnabled && teamId == null) {
3026+
if (statsEnabled && teamId == null
3027+
&& !METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION.contains(methodName)) {
30263028
teamId = teamIdCache.lookupOrResolve(token);
30273029
}
30283030
try {
@@ -3047,7 +3049,8 @@ protected <T extends SlackApiTextResponse> T postFormWithTokenAndParseResponse(
30473049
String token,
30483050
Class<T> clazz) throws IOException, SlackApiException {
30493051
String teamId = this.teamId.orElse(null);
3050-
if (statsEnabled && teamId == null) {
3052+
if (statsEnabled && teamId == null
3053+
&& !METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION.contains(methodName)) {
30513054
teamId = teamIdCache.lookupOrResolve(token);
30523055
}
30533056
try {
@@ -3089,7 +3092,8 @@ protected <T extends SlackApiTextResponse> T postMultipartAndParseResponse(
30893092
String token,
30903093
Class<T> clazz) throws IOException, SlackApiException {
30913094
String teamId = this.teamId.orElse(null);
3092-
if (statsEnabled && teamId == null) {
3095+
if (statsEnabled && teamId == null
3096+
&& !METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION.contains(methodName)) {
30933097
teamId = teamIdCache.lookupOrResolve(token);
30943098
}
30953099
try {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import okhttp3.Response;
1010

1111
import java.io.IOException;
12+
import java.util.Arrays;
13+
import java.util.List;
1214
import java.util.concurrent.ConcurrentHashMap;
1315
import java.util.concurrent.ConcurrentMap;
1416
import java.util.function.Function;
@@ -18,6 +20,14 @@
1820
@Slf4j
1921
public class TeamIdCache {
2022

23+
// As the tokens issued for "Sign in with Slack" does not work with auth.test API method,
24+
// we skip creating team_id cache for these API methods.
25+
public static final List<String> METHOD_NAMES_TO_SKIP_TEAM_ID_CACHE_RESOLUTION = Arrays.asList(
26+
"auth.revoke",
27+
"openid.connect.token",
28+
"openid.connect.userInfo"
29+
);
30+
2131
private static final ConcurrentMap<String, String> TOKEN_TO_TEAM_ID = new ConcurrentHashMap<>();
2232

2333
private final MethodsClientImpl methodsImpl;

0 commit comments

Comments
 (0)