-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR is the backend part of migrating slack app to the oath access token, which will resolve the limitation of single workspace. Doc: https://www.notion.so/Slack-OAuth-flow-14551bd6607c80d08a13f56c04a81abd What's included in this PR: 1. Add following API endpoints: - `GET /users/subscriptions/slack/oauth`: ger user's slack workspace name they installed - `POST /users/subscriptions/slack/oauth`: Post code from FE to slack API to exchange the access token, store information in DB - `DELETE /users/subscriptions/slack/oauth`: delete the user's slack information 2. Add back slack test API `POST /subscriptions/slack/test` 3. modify SlackTransporter logic to use the user's accessToken when sending messages 4. Add new slack fields and delete slackEmail fields in user table ## Related Issue <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> ## Notes <!-- Other thing to say --> 1. AccessToken is encrypted in the storage and is decrypted before it needs to be used. Encryption key is stored as an environment variable. 2. Backward compatible. If the user has subscribed Slack channel without a user access token, we will use the one in env var. ## Test <!--- Please describe in detail how you tested your changes locally. --> 1. Run local server 2. Pasting this URL in your browser (fill in the scope and client_id) `https://slack.com/oauth/v2/authorize?scope={scope}&client_id={client_id}` <img width="1464" alt="Screenshot 2024-11-24 at 9 24 53 PM" src="https://github.com/user-attachments/assets/c771efc8-4e8c-490c-a984-dc81d20a4ae3"> 3. Choose a workspace and click allow button, pull the code in the callback request from devtools <img width="736" alt="Screenshot 2024-11-24 at 9 26 05 PM" src="https://github.com/user-attachments/assets/b5a9e8fa-c22b-45f9-9d3b-3cf490bd3e53"> 4. Use the code to hit `POST /users/subscriptions/slack/oauth` 5. Hit `POST /subscriptions/slack/test` to see if you got the slack message 6. Hit `GET /users/subscriptions/slack/oauth` and `DELETE /users/subscriptions/slack/oauth` to see if it works correctly ## Screenshots (if appropriate): <!--- Add screenshots of your changes here --> N/A ## TODO - [x] Clear `console.log` or `console.error` for debug usage - [ ] Update the documentation `recnet-docs` if needed - [ ] Update environment variables in staging and production env - [ ] Add unit tests - [ ] Add migration announcement with specific deadline
- Loading branch information
Showing
23 changed files
with
430 additions
and
17 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
6 changes: 6 additions & 0 deletions
6
apps/recnet-api/prisma/migrations/20241124232108_add_slack_oauth/down.sql
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,6 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "slackAccessToken", | ||
DROP COLUMN "slackUserId", | ||
DROP COLUMN "slackWorkspaceName", | ||
ADD COLUMN "slackEmail" VARCHAR(128); | ||
|
11 changes: 11 additions & 0 deletions
11
apps/recnet-api/prisma/migrations/20241124232108_add_slack_oauth/migration.sql
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,11 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `slackEmail` on the `User` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "slackEmail", | ||
ADD COLUMN "slackAccessToken" VARCHAR(128), | ||
ADD COLUMN "slackUserId" VARCHAR(64), | ||
ADD COLUMN "slackWorkspaceName" VARCHAR(64); |
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
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
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.