Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions json-logs/samples/api/oauth.v2.beginShortTokenRotation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"ok": false,
"error": "",
"needed": "",
"provided": "",
"new_token": "",
"response_metadata": {
"messages": [
""
]
},
"warning": ""
}
1 change: 1 addition & 0 deletions metadata/web-api/rate_limit_tiers.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
"oauth.access": "Tier4",
"oauth.token": "Tier4",
"oauth.v2.access": "Tier4",
"oauth.v2.beginShortTokenRotation": "Tier2",
"oauth.v2.exchange": "Tier3",
"openid.connect.token": "Tier4",
"openid.connect.userInfo": "Tier3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import com.slack.api.methods.request.oauth.OAuthAccessRequest;
import com.slack.api.methods.request.oauth.OAuthTokenRequest;
import com.slack.api.methods.request.oauth.OAuthV2AccessRequest;
import com.slack.api.methods.request.oauth.OAuthV2BeginShortTokenRotationRequest;
import com.slack.api.methods.request.oauth.OAuthV2ExchangeRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectTokenRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectUserInfoRequest;
Expand Down Expand Up @@ -276,6 +277,7 @@
import com.slack.api.methods.response.oauth.OAuthAccessResponse;
import com.slack.api.methods.response.oauth.OAuthTokenResponse;
import com.slack.api.methods.response.oauth.OAuthV2AccessResponse;
import com.slack.api.methods.response.oauth.OAuthV2BeginShortTokenRotationResponse;
import com.slack.api.methods.response.oauth.OAuthV2ExchangeResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectTokenResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectUserInfoResponse;
Expand Down Expand Up @@ -1481,6 +1483,10 @@ CompletableFuture<AdminConversationsWhitelistListGroupsLinkedToChannelResponse>

CompletableFuture<OAuthV2AccessResponse> oauthV2Access(RequestConfigurator<OAuthV2AccessRequest.OAuthV2AccessRequestBuilder> req);

CompletableFuture<OAuthV2BeginShortTokenRotationResponse> oauthV2BeginShortTokenRotation(OAuthV2BeginShortTokenRotationRequest req);

CompletableFuture<OAuthV2BeginShortTokenRotationResponse> oauthV2BeginShortTokenRotation(RequestConfigurator<OAuthV2BeginShortTokenRotationRequest.OAuthV2BeginShortTokenRotationRequestBuilder> req);

CompletableFuture<OAuthV2ExchangeResponse> oauthV2Exchange(OAuthV2ExchangeRequest req);

CompletableFuture<OAuthV2ExchangeResponse> oauthV2Exchange(RequestConfigurator<OAuthV2ExchangeRequest.OAuthV2ExchangeRequestBuilder> req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ private Methods() {

public static final String OAUTH_ACCESS = "oauth.access";
public static final String OAUTH_V2_ACCESS = "oauth.v2.access";
public static final String OAUTH_V2_BEGIN_SHORT_TOKEN_ROTATION = "oauth.v2.beginShortTokenRotation";
public static final String OAUTH_V2_EXCHANGE = "oauth.v2.exchange";
public static final String OAUTH_TOKEN = "oauth.token";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import com.slack.api.methods.request.oauth.OAuthAccessRequest;
import com.slack.api.methods.request.oauth.OAuthTokenRequest;
import com.slack.api.methods.request.oauth.OAuthV2AccessRequest;
import com.slack.api.methods.request.oauth.OAuthV2BeginShortTokenRotationRequest;
import com.slack.api.methods.request.oauth.OAuthV2ExchangeRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectTokenRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectUserInfoRequest;
Expand Down Expand Up @@ -301,6 +302,7 @@
import com.slack.api.methods.response.oauth.OAuthAccessResponse;
import com.slack.api.methods.response.oauth.OAuthTokenResponse;
import com.slack.api.methods.response.oauth.OAuthV2AccessResponse;
import com.slack.api.methods.response.oauth.OAuthV2BeginShortTokenRotationResponse;
import com.slack.api.methods.response.oauth.OAuthV2ExchangeResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectTokenResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectUserInfoResponse;
Expand Down Expand Up @@ -2593,6 +2595,13 @@ OAuthAccessResponse oauthAccess(RequestConfigurator<OAuthAccessRequest.OAuthAcce
OAuthV2AccessResponse oauthV2Access(RequestConfigurator<OAuthV2AccessRequest.OAuthV2AccessRequestBuilder> req)
throws IOException, SlackApiException;

OAuthV2BeginShortTokenRotationResponse oauthV2BeginShortTokenRotation(OAuthV2BeginShortTokenRotationRequest req)
throws IOException, SlackApiException;

OAuthV2BeginShortTokenRotationResponse oauthV2BeginShortTokenRotation(
RequestConfigurator<OAuthV2BeginShortTokenRotationRequest.OAuthV2BeginShortTokenRotationRequestBuilder> req)
throws IOException, SlackApiException;

OAuthV2ExchangeResponse oauthV2Exchange(OAuthV2ExchangeRequest req) throws IOException, SlackApiException;

OAuthV2ExchangeResponse oauthV2Exchange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ public static void setRateLimitTier(String methodName, MethodsRateLimitTier tier
setRateLimitTier(OAUTH_ACCESS, Tier4);
setRateLimitTier(OAUTH_TOKEN, Tier4);
setRateLimitTier(OAUTH_V2_ACCESS, Tier4);
setRateLimitTier(OAUTH_V2_BEGIN_SHORT_TOKEN_ROTATION, Tier2);
setRateLimitTier(OAUTH_V2_EXCHANGE, Tier3);

setRateLimitTier(OPENID_CONNECT_TOKEN, Tier4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import com.slack.api.methods.request.mpim.*;
import com.slack.api.methods.request.oauth.OAuthAccessRequest;
import com.slack.api.methods.request.oauth.OAuthTokenRequest;
import com.slack.api.methods.request.oauth.OAuthV2BeginShortTokenRotationRequest;
import com.slack.api.methods.request.oauth.OAuthV2ExchangeRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectUserInfoRequest;
import com.slack.api.methods.request.pins.PinsAddRequest;
Expand Down Expand Up @@ -2902,6 +2903,13 @@ public static FormBody.Builder toForm(OAuthTokenRequest req) {
return form;
}

public static FormBody.Builder toForm(OAuthV2BeginShortTokenRotationRequest req) {
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("client_id", req.getClientId(), form);
setIfNotNull("client_secret", req.getClientSecret(), form);
return form;
}

public static FormBody.Builder toForm(OAuthV2ExchangeRequest req) {
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("client_id", req.getClientId(), form);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import com.slack.api.methods.request.oauth.OAuthAccessRequest;
import com.slack.api.methods.request.oauth.OAuthTokenRequest;
import com.slack.api.methods.request.oauth.OAuthV2AccessRequest;
import com.slack.api.methods.request.oauth.OAuthV2BeginShortTokenRotationRequest;
import com.slack.api.methods.request.oauth.OAuthV2ExchangeRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectTokenRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectUserInfoRequest;
Expand Down Expand Up @@ -280,6 +281,7 @@
import com.slack.api.methods.response.oauth.OAuthAccessResponse;
import com.slack.api.methods.response.oauth.OAuthTokenResponse;
import com.slack.api.methods.response.oauth.OAuthV2AccessResponse;
import com.slack.api.methods.response.oauth.OAuthV2BeginShortTokenRotationResponse;
import com.slack.api.methods.response.oauth.OAuthV2ExchangeResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectTokenResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectUserInfoResponse;
Expand Down Expand Up @@ -2627,6 +2629,16 @@ public CompletableFuture<OAuthV2AccessResponse> oauthV2Access(RequestConfigurato
return oauthV2Access(req.configure(OAuthV2AccessRequest.builder()).build());
}

@Override
public CompletableFuture<OAuthV2BeginShortTokenRotationResponse> oauthV2BeginShortTokenRotation(OAuthV2BeginShortTokenRotationRequest req) {
return executor.execute(OAUTH_V2_BEGIN_SHORT_TOKEN_ROTATION, toMap(req), () -> methods.oauthV2BeginShortTokenRotation(req));
}

@Override
public CompletableFuture<OAuthV2BeginShortTokenRotationResponse> oauthV2BeginShortTokenRotation(RequestConfigurator<OAuthV2BeginShortTokenRotationRequest.OAuthV2BeginShortTokenRotationRequestBuilder> req) {
return oauthV2BeginShortTokenRotation(req.configure(OAuthV2BeginShortTokenRotationRequest.builder()).build());
}

@Override
public CompletableFuture<OAuthV2ExchangeResponse> oauthV2Exchange(OAuthV2ExchangeRequest req) {
return executor.execute(OAUTH_V2_EXCHANGE, toMap(req), () -> methods.oauthV2Exchange(req));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import com.slack.api.methods.request.oauth.OAuthAccessRequest;
import com.slack.api.methods.request.oauth.OAuthTokenRequest;
import com.slack.api.methods.request.oauth.OAuthV2AccessRequest;
import com.slack.api.methods.request.oauth.OAuthV2BeginShortTokenRotationRequest;
import com.slack.api.methods.request.oauth.OAuthV2ExchangeRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectTokenRequest;
import com.slack.api.methods.request.openid.connect.OpenIDConnectUserInfoRequest;
Expand Down Expand Up @@ -303,6 +304,7 @@
import com.slack.api.methods.response.oauth.OAuthAccessResponse;
import com.slack.api.methods.response.oauth.OAuthTokenResponse;
import com.slack.api.methods.response.oauth.OAuthV2AccessResponse;
import com.slack.api.methods.response.oauth.OAuthV2BeginShortTokenRotationResponse;
import com.slack.api.methods.response.oauth.OAuthV2ExchangeResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectTokenResponse;
import com.slack.api.methods.response.openid.connect.OpenIDConnectUserInfoResponse;
Expand Down Expand Up @@ -3279,6 +3281,16 @@ public OAuthV2AccessResponse oauthV2Access(RequestConfigurator<OAuthV2AccessRequ
return oauthV2Access(req.configure(OAuthV2AccessRequest.builder()).build());
}

@Override
public OAuthV2BeginShortTokenRotationResponse oauthV2BeginShortTokenRotation(OAuthV2BeginShortTokenRotationRequest req) throws IOException, SlackApiException {
return postFormWithTokenAndParseResponse(toForm(req), Methods.OAUTH_V2_BEGIN_SHORT_TOKEN_ROTATION, getToken(req), OAuthV2BeginShortTokenRotationResponse.class);
}

@Override
public OAuthV2BeginShortTokenRotationResponse oauthV2BeginShortTokenRotation(RequestConfigurator<OAuthV2BeginShortTokenRotationRequest.OAuthV2BeginShortTokenRotationRequestBuilder> req) throws IOException, SlackApiException {
return oauthV2BeginShortTokenRotation(req.configure(OAuthV2BeginShortTokenRotationRequest.builder()).build());
}

@Override
public OAuthV2ExchangeResponse oauthV2Exchange(OAuthV2ExchangeRequest req) throws IOException, SlackApiException {
return postFormAndParseResponse(toForm(req), Methods.OAUTH_V2_EXCHANGE, OAuthV2ExchangeResponse.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.slack.api.methods.request.oauth;

import com.slack.api.methods.SlackApiRequest;
import lombok.Builder;
import lombok.Data;

/**
* https://docs.slack.dev/reference/methods/oauth.v2.beginShortTokenRotation
*/
@Data
@Builder
public class OAuthV2BeginShortTokenRotationRequest implements SlackApiRequest {

/**
* Issued when you created your application. Must be the app the token being rotated was issued to.
*/
private String clientId;

/**
* Issued when you created your application.
*/
private String clientSecret;

/**
* The xoxp token being rotated.
*/
private String token;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.slack.api.methods.response.oauth;

import com.slack.api.methods.SlackApiTextResponse;
import com.slack.api.model.ErrorResponseMetadata;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
* https://docs.slack.dev/reference/methods/oauth.v2.beginShortTokenRotation
*/
@Data
public class OAuthV2BeginShortTokenRotationResponse implements SlackApiTextResponse {

private boolean ok;
private String warning;
private String error;
private String needed;
private String provided;
private transient Map<String, List<String>> httpResponseHeaders;

private String newToken;
private ErrorResponseMetadata responseMetadata;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,20 @@ public void exchange() {
assertThat(response.getExpiresIn(), is(43200));
}

@Test
public void beginShortTokenRotation() throws Exception {
assertThat(slack.methods().oauthV2BeginShortTokenRotation(r -> r
.clientId("4123121235.9872358710")
.clientSecret("e1b9e11dfcd19c1982d5de12921e17e8c")
.token("xoxp-12345-67890-1928471-abcdefg")).isOk(), is(true));
}

@Test
public void beginShortTokenRotation_async() throws Exception {
assertThat(slack.methodsAsync().oauthV2BeginShortTokenRotation(r -> r
.clientId("4123121235.9872358710")
.clientSecret("e1b9e11dfcd19c1982d5de12921e17e8c")
.token("xoxp-12345-67890-1928471-abcdefg")).get().isOk(), is(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.slack.api.methods.response.oauth.OAuthAccessResponse;
import com.slack.api.methods.response.oauth.OAuthTokenResponse;
import com.slack.api.methods.response.oauth.OAuthV2AccessResponse;
import com.slack.api.methods.response.oauth.OAuthV2BeginShortTokenRotationResponse;
import com.slack.api.methods.response.oauth.OAuthV2ExchangeResponse;
import com.slack.api.model.ErrorResponseMetadata;
import config.Constants;
import config.SlackTestConfig;
import lombok.extern.slf4j.Slf4j;
import org.junit.AfterClass;
Expand Down Expand Up @@ -77,6 +79,19 @@ public void accessV2Exchange() throws IOException, SlackApiException {
assertThat(response.isOk(), is(false));
}

String userToken = System.getenv(Constants.SLACK_SDK_TEST_USER_TOKEN);

@Test
public void beginShortTokenRotation() throws IOException, SlackApiException {
// The example client_id from the docs is not the app this token was issued to
OAuthV2BeginShortTokenRotationResponse response = slack.methods().oauthV2BeginShortTokenRotation(r -> r
.clientId("4123121235.9872358710")
.clientSecret("e1b9e11dfcd19c1982d5de12921e17e8c")
.token(userToken));
assertThat(response.getError(), is("invalid_client_id"));
assertThat(response.isOk(), is(false));
}

// TODO: valid test; currently just checking the API access
@Test
@Ignore
Expand Down
Loading