Skip to main content

oauth.v2.beginShortTokenRotation method

Facts

DescriptionCall this to rotate the secret on an old API token with a short secret. Must be paired with a call to oauth.v2.completeShortTokenRotation to confirm the change.
Method Access
POST https://slack.com/api/oauth.v2.beginShortTokenRotation
ScopesNo scopes required
Content types
application/x-www-form-urlencoded
application/json

Arguments

Required arguments

client_idstringRequired

Issued when you created your application. Must be the app the token being rotated was issued to.

Example: 4123121235.9872358710
client_secretstringRequired

Issued when you created your application.

Example: e1b9e11dfcd19c1982d5de12921e17e8c
tokenstringRequired

The xoxp token being rotated.

Example: xoxp-12345-67890-1928471-abcdefg

Usage info

Use this API method alongside the oauth.v2.completeShortTokenRotation method to rotate a short-secret user token created before August 19, 2016 to a more secure token with a longer 32-character secret.

This is a one-time rotation. If you want to rotate token secrets periodically, see the token rotation documentation for more details.

1. Identify your tokens with short secret lengths

If you have timestamps available, you can filter for anything created prior to August 19, 2016.

If you aren't sure when a token was created, you can parse the strings and identify any with secrets fewer than 32 characters. The token is divided into several sections, separated by a - character. The final section is the secret. In this example, the secret is d6bc768406e5c2e6958cfc399b438004. Tokens created before August 2016 may have secrets with 6 or 10 characters instead of 32.

// A Slack token with a long secret
xoxp-111-222-333-d6bc768406e5c2e6958cfc399b438004

// Slack tokens created before August 2016
xoxp-111-222-333-d6bc76
xoxp-111-222-333-d6bc768412

2. Grab your app's client_id and client_secret credentials

These credentials are the same credentials you use with the oauth.v2.access method. You can find them on the Basic Information page of your app's configuration. The client_id must belong to the app the token was issued to.

3. Call the oauth.v2.beginShortTokenRotation method

For each token, call the oauth.v2.beginShortTokenRotation method and pass the token you want to update, along with your client_id and client_secret.

curl -X POST https://slack.com/api/oauth.v2.beginShortTokenRotation \
-H "Authorization: Bearer xoxp-35441797610-35912028499-1325414073906-d6bc768412" \
-H "Content-type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=4123121235.9872358710" \
--data-urlencode "client_secret=e1b9e11dfcd19c1982d5de12921e17e8c"

The response will contain a new_token field.

{
"ok": true,
"new_token": "xoxp-35441797610-35912028499-1325414073906-6e813caca4c605e2a04f66eedf11dc09"
}

This change does not take effect until you complete the flow. Do not overwrite your original token until the flow is complete.

For each token, the rotation must be completed within 10 minutes. If more than 10 minutes pass between calling the oauth.v2.beginShortTokenRotation and oauth.v2.completeShortTokenRotation methods, you will need to start over.

4. Call the oauth.v2.completeShortTokenRotation method

Pass the original short token in the Authorization header of the call. Pass the new replacement token as the new_token parameter, along with the same client_id and client_secret.

curl -X POST https://slack.com/api/oauth.v2.completeShortTokenRotation \
-H "Authorization: Bearer xoxp-35441797610-35912028499-1325414073906-d6bc768412" \
-H "Content-type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=4123121235.9872358710" \
--data-urlencode "client_secret=e1b9e11dfcd19c1982d5de12921e17e8c" \
--data-urlencode "new_token=xoxp-35441797610-35912028499-1325414073906-6e813caca4c605e2a04f66eedf11dc09"

If the response to this API call is successful, the original token will be invalidated and the new token will go live. The new token will be exactly the same as the original, but with a longer secret. The response echoes it back in the token field.

{
"ok": true,
"token": "xoxp-35441797610-35912028499-1325414073906-6e813caca4c605e2a04f66eedf11dc09"
}

If you do not get a successful response from oauth.v2.completeShortTokenRotation, the rotation may not have been completed. Call auth.test with the original and new token to check which is valid.

5. Call auth.test to confirm the new token is valid

If everything looks good, update your database with the new token.


Response

Successful start of a short token rotation. The new_token is not active until the rotation is completed with oauth.v2.completeShortTokenRotation.

{
"ok": true,
"new_token": "xoxp-35441797610-35912028499-1325414073906-6e813caca4c605e2a04f66eedf11dc09"
}

Errors

This table lists the expected errors that this method could return. However, other errors can be returned in the case where the service is down or other unexpected factors affect processing. Callers should always check the value of the ok parameter in the response.

Error
Description
access_denied

Access to a resource specified in the request is denied.

accesslimited

Access to this method is limited on the current network

account_inactive

Authentication token is for a deleted user or workspace when using a bot token.

bad_client_secret

Value passed for client_secret was invalid.

deprecated_endpoint

The endpoint has been deprecated.

ekm_access_denied

Administrators have suspended the ability to post a message.

enterprise_is_restricted

The method cannot be called from an Enterprise.

fatal_error

The server could not complete your operation(s) without encountering a catastrophic error. It's possible some aspect of the operation succeeded before the error was raised.

internal_error

A server-side error occurred.

internal_error

The server could not complete your operation(s) without encountering an error, likely due to a transient issue on our end. It's possible some aspect of the operation succeeded before the error was raised.

invalid_arg_name

The method was passed an argument whose name falls outside the bounds of accepted or expected values. This includes very long names and names with non-alphanumeric characters other than _. If you get this error, it is typically an indication that you have made a very malformed API call.

invalid_arguments

The method was called with invalid arguments.

invalid_array_arg

The method was passed an array as an argument. Please only input valid strings.

invalid_auth

Some aspect of authentication cannot be validated. Either the provided token is invalid or the request originates from an IP address disallowed from making the request.

invalid_charset

The method was called via a POST request, but the charset specified in the Content-Type header was invalid. Valid charset names are: utf-8 iso-8859-1.

invalid_client_id

Value passed for client_id was invalid, or is not the app the token being rotated was issued to.

invalid_form_data

The method was called via a POST request with Content-Type application/x-www-form-urlencoded or multipart/form-data, but the form data was either missing or syntactically invalid.

invalid_post_type

The method was called via a POST request, but the specified Content-Type was invalid. Valid types are: application/json application/x-www-form-urlencoded multipart/form-data text/plain.

invalid_token

This token is invalid.

method_deprecated

The method has been deprecated.

missing_post_type

The method was called via a POST request and included a data payload, but the request did not include a Content-Type header.

missing_scope

The token used is not granted the specific scope permissions required to complete this request.

no_permission

The workspace token used in this request does not have the permissions necessary to complete the request. Make sure your app is a member of the conversation it's attempting to post a message to.

not_allowed_token_type

The token type used in this request is not allowed.

not_authed

No authentication token provided.

org_login_required

The workspace is undergoing an enterprise migration and will not be available until migration is complete.

ratelimited

The request has been ratelimited. Refer to the Retry-After header for when to retry the request.

request_timeout

The method was called via a POST request, but the POST data was either missing or truncated.

service_unavailable

The service is temporarily unavailable

team_access_not_granted

The token used is not granted the specific workspace access required to complete this request.

team_added_to_org

The workspace associated with your request is currently undergoing migration to an Enterprise Organization. Web API and other platform operations will be intermittently unavailable until the transition is complete.

token_expired

Authentication token has expired

token_revoked

Authentication token is for a deleted user or workspace or the app has been removed when using a user token.

token_too_long

This token is not short enough to be rotated.

two_factor_setup_required

Two factor setup is required.