New Features
Token Rotation Support
This version includes the token rotation feature support for better security. Refer to [the API document](https://api.slack.com/authentication/rotation) for the general information about the feature.
How to enable token rotation with this SDK
Apart from the column additions for the feature (specifically, refresh token + expiration date time) and the corresponding changes in your app code, no significant code is needed. Checking the example apps using Flask, Sanic in [this directory](https://github.com/slackapi/python-slack-sdk/tree/main/integration_tests/samples/token_rotation) can be helpful to learn what to do.
In a nutshell, you can call the following `rotate_tokens` method before handling every single incoming request from Slack. As long as your `InstallationStore` support the token rotation patterns, the code below should work as-is.
python
from slack_sdk.oauth.token_rotation import TokenRotator
from slack_sdk.oauth.installation_store import FileInstallationStore
This instance can be singleton; thread-safe
token_rotator = TokenRotator(
These are required for refreshing tokens
client_id=client_id,
client_secret=client_secret,
)
Your own InstallationStore here
installation_store = FileInstallationStore()
def rotate_tokens(
enterprise_id: Optional[str] = None,
team_id: Optional[str] = None,
user_id: Optional[str] = None,
is_enterprise_install: Optional[bool] = None,
):
installation = installation_store.find_installation(
enterprise_id=enterprise_id,
team_id=team_id,
user_id=user_id,
is_enterprise_install=is_enterprise_install,
)
if installation is not None:
If rotation does not occur, refreshed_installation is None
refreshed_installation = token_rotator.perform_token_rotation(installation=installation)
if refreshed_installation is not None:
Save the new access token for the following processes
installation_store.save(refreshed_installation)
Migration guide for `SQLAlchemyInstallationStore` users
If your app uses the built-in `SQLAlchemyInstallationStore` for managing Slack app installations, adding the following database columns is required for this version upgrade. Refer to [the code](https://github.com/slackapi/python-slack-sdk/tree/main/slack_sdk/oauth/installation_store/sqlalchemy) to check the complete ones.
Also, since this version, all the table columns for string data have their max length for better compatibility with MySQL. We recommend setting the same ones for your models.
slack_installations
* `Column("bot_refresh_token", String(200)),`
* `Column("bot_token_expires_at", DateTime),`
* `Column("user_refresh_token", String(200)),`
* `Column("user_token_expires_at", DateTime),`
slack_bots
* `Column("bot_refresh_token", String(200)),`
* `Column("bot_token_expires_at", DateTime),`
Changes
* 1060 Add token rotation feature support - Thanks seratch
* 1040 Set max length for string columns in SQLAlchemy models for MySQL compatibility - Thanks tattee
* 1047 Make WebhookClient (sync/async) send method accept link unfurl params - Thanks srajiang
* 1061 WebClient's paginated response iterator does not work for admin.conversations.search API - Thanks seratch
* 1054 1053 conversations_invite() fails with "error: no_user" - Thanks seratch noperator
* 1044 Updates PythOnBoardingBot tutorial sample to use bolt-python - Thanks srajiang
* 1048 Update command in maintainers guide - Thanks srajiang
---
* All issues/pull requests: https://github.com/slackapi/python-slack-sdk/milestone/38?closed=1
* All changes: https://github.com/slackapi/python-slack-sdk/compare/v3.7.0...v3.8.0