def test_instantiation(self): oauth_flow = OAuthFlow.sqlite3( database="./logs/test_db", client_id="111.222", client_secret="xxx", scopes=["chat:write", "commands"], ) assert oauth_flow is not None assert oauth_flow.logger is not None assert oauth_flow.client is not None
def test_handle_installation(self): oauth_flow = OAuthFlow.sqlite3( client=WebClient(base_url=self.mock_api_server_base_url), database="./logs/test_db", client_id="111.222", client_secret="xxx", scopes=["chat:write", "commands"], ) req = BoltRequest(body="") resp = oauth_flow.handle_installation(req) assert resp.status == 200 assert resp.headers.get("content-type") == ["text/html; charset=utf-8"] assert "https://slack.com/oauth/v2/authorize?state=" in resp.body
def test_handle_callback_invalid_state(self): oauth_flow = OAuthFlow.sqlite3( client=WebClient(base_url=self.mock_api_server_base_url), database="./logs/test_db", client_id="111.222", client_secret="xxx", scopes=["chat:write", "commands"], ) state = oauth_flow.issue_new_state(None) req = BoltRequest( body="", query=f"code=foo&state=invalid", headers={ "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"] }, ) resp = oauth_flow.handle_callback(req) assert resp.status == 400
def test_handle_callback_using_options(self): def success(args: SuccessArgs) -> BoltResponse: assert args.request is not None return BoltResponse(status=200, body="customized") def failure(args: FailureArgs) -> BoltResponse: assert args.request is not None assert args.reason is not None return BoltResponse(status=502, body="customized") oauth_flow = OAuthFlow.sqlite3( client=WebClient(base_url=self.mock_api_server_base_url), database="./logs/test_db", client_id="111.222", client_secret="xxx", scopes=["chat:write", "commands"], callback_options=CallbackOptions(success=success, failure=failure), ) state = oauth_flow.issue_new_state(None) req = BoltRequest( body="", query=f"code=foo&state={state}", headers={ "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"] }, ) resp = oauth_flow.handle_callback(req) assert resp.status == 200 assert resp.body == "customized" state = oauth_flow.issue_new_state(None) req = BoltRequest( body="", query=f"code=foo&state=invalid", headers={ "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"] }, ) resp = oauth_flow.handle_callback(req) assert resp.status == 502 assert resp.body == "customized"
def test_handle_callback(self): oauth_flow = OAuthFlow.sqlite3( client=WebClient(base_url=self.mock_api_server_base_url), database="./logs/test_db", client_id="111.222", client_secret="xxx", scopes=["chat:write", "commands"], success_url="https://www.example.com/completion", failure_url="https://www.example.com/failure", ) state = oauth_flow.issue_new_state(None) req = BoltRequest( body="", query=f"code=foo&state={state}", headers={ "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"] }, ) resp = oauth_flow.handle_callback(req) assert resp.status == 200 assert "https://www.example.com/completion" in resp.body
# ------------------------------------------------ # instead of slack_bolt in requirements.txt import sys sys.path.insert(1, "..") # ------------------------------------------------ import logging logging.basicConfig(level=logging.DEBUG) from slack_bolt import App from slack_bolt.oauth import OAuthFlow app = App(oauth_flow=OAuthFlow.sqlite3(database="./slackapp.db")) @app.event("app_mention") def handle_app_mentions(payload, say, logger): logger.info(payload) say("What's up?") if __name__ == "__main__": app.start(3000) # pip install slack_bolt # export SLACK_SIGNING_SECRET=*** # export SLACK_BOT_TOKEN=xoxb-*** # export SLACK_CLIENT_ID=111.111 # export SLACK_CLIENT_SECRET=***