-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #254 Add built-in tokens_revoked/app_uninstalled event handlers
- Loading branch information
Showing
8 changed files
with
496 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from slack_bolt.context.async_context import AsyncBoltContext | ||
from slack_sdk.oauth.installation_store.async_installation_store import ( | ||
AsyncInstallationStore, | ||
) | ||
|
||
|
||
class AsyncTokenRevocationListeners: | ||
"""Listener functions to handle token revocation / uninstallation events""" | ||
|
||
installation_store: AsyncInstallationStore | ||
|
||
def __init__(self, installation_store: AsyncInstallationStore): | ||
self.installation_store = installation_store | ||
|
||
async def handle_tokens_revoked_events( | ||
self, event: dict, context: AsyncBoltContext | ||
) -> None: | ||
user_ids = event.get("tokens", {}).get("oauth", []) | ||
if len(user_ids) > 0: | ||
for user_id in user_ids: | ||
await self.installation_store.async_delete_installation( | ||
enterprise_id=context.enterprise_id, | ||
team_id=context.team_id, | ||
user_id=user_id, | ||
) | ||
bots = event.get("tokens", {}).get("bot", []) | ||
if len(bots) > 0: | ||
await self.installation_store.async_delete_bot( | ||
enterprise_id=context.enterprise_id, | ||
team_id=context.team_id, | ||
) | ||
|
||
async def handle_app_uninstalled_events(self, context: AsyncBoltContext) -> None: | ||
await self.installation_store.async_delete_all( | ||
enterprise_id=context.enterprise_id, | ||
team_id=context.team_id, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from slack_sdk.oauth import InstallationStore | ||
|
||
from slack_bolt.context.context import BoltContext | ||
from slack_sdk.oauth.installation_store.installation_store import InstallationStore | ||
|
||
|
||
class TokenRevocationListeners: | ||
"""Listener functions to handle token revocation / uninstallation events""" | ||
|
||
installation_store: InstallationStore | ||
|
||
def __init__(self, installation_store: InstallationStore): | ||
self.installation_store = installation_store | ||
|
||
def handle_tokens_revoked_events(self, event: dict, context: BoltContext) -> None: | ||
user_ids = event.get("tokens", {}).get("oauth", []) | ||
if len(user_ids) > 0: | ||
for user_id in user_ids: | ||
self.installation_store.delete_installation( | ||
enterprise_id=context.enterprise_id, | ||
team_id=context.team_id, | ||
user_id=user_id, | ||
) | ||
bots = event.get("tokens", {}).get("bot", []) | ||
if len(bots) > 0: | ||
self.installation_store.delete_bot( | ||
enterprise_id=context.enterprise_id, | ||
team_id=context.team_id, | ||
) | ||
|
||
def handle_app_uninstalled_events(self, context: BoltContext) -> None: | ||
self.installation_store.delete_all( | ||
enterprise_id=context.enterprise_id, | ||
team_id=context.team_id, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.