Skip to content

Commit 7913e7b

Browse files
authored
Merge pull request #455 from seratch/no-team-no-redirect-uri
Update OAuth flow to complete with some cases
2 parents 39fb84a + 79a3cb2 commit 7913e7b

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

bolt/src/main/java/com/slack/api/bolt/service/builtin/oauth/default_impl/OAuthV2DefaultSuccessHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public Response handle(OAuthCallbackRequest request, Response response, OAuthV2A
3030
if (o.getEnterprise() != null) {
3131
context.setEnterpriseId(o.getEnterprise().getId());
3232
}
33-
context.setTeamId(o.getTeam().getId());
33+
// "team" can be null for org-level installation
34+
String teamId = o.getTeam() != null ? o.getTeam().getId() : null;
35+
String teamName = o.getTeam() != null ? o.getTeam().getName() : null;
36+
context.setTeamId(teamId);
3437
context.setBotUserId(o.getBotUserId());
3538
context.setBotToken(o.getAccessToken());
3639
context.setRequestUserId(o.getAuthedUser().getId());
@@ -40,8 +43,8 @@ public Response handle(OAuthCallbackRequest request, Response response, OAuthV2A
4043
.botUserId(o.getBotUserId())
4144
.botAccessToken(o.getAccessToken())
4245
.enterpriseId(o.getEnterprise() != null ? o.getEnterprise().getId() : null)
43-
.teamId(o.getTeam().getId())
44-
.teamName(o.getTeam().getName())
46+
.teamId(teamId)
47+
.teamName(teamName)
4548
.scope(o.getScope())
4649
.botScope(o.getScope())
4750
.installedAt(System.currentTimeMillis());

codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ coverage:
33
project:
44
default:
55
threshold: 0.3%
6+
patch:
7+
default:
8+
target: 50%
9+

slack-app-backend/src/main/java/com/slack/api/app_backend/oauth/OAuthFlowOperator.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,25 @@ public OAuthFlowOperator(Slack slack, SlackAppConfig config) {
2222
}
2323

2424
public OAuthAccessResponse callOAuthAccessMethod(VerificationCodePayload payload) throws IOException, SlackApiException {
25-
return slack.methods().oauthAccess(OAuthAccessRequest.builder()
25+
OAuthAccessRequest.OAuthAccessRequestBuilder apiRequest = OAuthAccessRequest.builder()
2626
.clientId(config.getClientId())
2727
.clientSecret(config.getClientSecret())
28-
.code(payload.getCode())
29-
.redirectUri(config.getRedirectUri())
30-
.build());
28+
.code(payload.getCode());
29+
if (config.getRedirectUri() != null) {
30+
apiRequest = apiRequest.redirectUri(config.getRedirectUri());
31+
}
32+
return slack.methods().oauthAccess(apiRequest.build());
3133
}
3234

3335
public OAuthV2AccessResponse callOAuthV2AccessMethod(VerificationCodePayload payload) throws IOException, SlackApiException {
34-
return slack.methods().oauthV2Access(OAuthV2AccessRequest.builder()
36+
OAuthV2AccessRequest.OAuthV2AccessRequestBuilder apiRequest = OAuthV2AccessRequest.builder()
3537
.clientId(config.getClientId())
3638
.clientSecret(config.getClientSecret())
37-
.code(payload.getCode())
38-
.redirectUri(config.getRedirectUri())
39-
.build());
39+
.code(payload.getCode());
40+
if (config.getRedirectUri() != null) {
41+
apiRequest = apiRequest.redirectUri(config.getRedirectUri());
42+
}
43+
return slack.methods().oauthV2Access(apiRequest.build());
4044
}
4145

4246
}

0 commit comments

Comments
 (0)