Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[recnet-api] Slack oauth API #364

Merged
merged 12 commits into from
Nov 25, 2024
Merged

[recnet-api] Slack oauth API #364

merged 12 commits into from
Nov 25, 2024

Conversation

joannechen1223
Copy link
Collaborator

@joannechen1223 joannechen1223 commented Nov 25, 2024

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
  1. Add back slack test API POST /subscriptions/slack/test
  2. modify SlackTransporter logic to use the user's accessToken when sending messages
  3. Add new slack fields and delete slackEmail fields in user table

Related Issue

Notes

  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

  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}
Screenshot 2024-11-24 at 9 24 53 PM
  1. Choose a workspace and click allow button, pull the code in the callback request from devtools
Screenshot 2024-11-24 at 9 26 05 PM 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):

N/A

TODO

  • 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

@joannechen1223 joannechen1223 self-assigned this Nov 25, 2024
Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
recnet ⬜️ Ignored (Inspect) Visit Preview Nov 25, 2024 11:05pm
recnet-docs ⬜️ Ignored (Inspect) Visit Preview Nov 25, 2024 11:05pm

Copy link
Collaborator

@swh00tw swh00tw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add some document somewhere (maybe in notion or use comment or both) about

  1. How you do the encryption/decryption (which algo we choose)
  2. The decision and more context about backward compatibility

apps/recnet-api/src/config/common.config.ts Outdated Show resolved Hide resolved
apps/recnet-api/src/utils/index.ts Show resolved Hide resolved
apps/recnet-api/src/modules/user/user.controller.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@swh00tw swh00tw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great works! I've tested the endpoints. Please fix the failed test before merge.

@joannechen1223 joannechen1223 merged commit 2252601 into dev Nov 25, 2024
4 checks passed
@joannechen1223 joannechen1223 deleted the recnet-api/slack-oauth branch November 25, 2024 23:34
@github-actions github-actions bot mentioned this pull request Nov 25, 2024
joannechen1223 added a commit that referenced this pull request Dec 3, 2024
## RecNet auto-release action
This is an auto-generated PR by recnet-release-action 🤖
Please make sure to test your changes in staging before merging. 
## Related Issues
- #261
- #64
## Related PRs
- #369
- #361
- #365
- #364
- #362
## Staging links
recnet-web:
[https://vercel.live/link/recnet-git-dev-recnet-542617e7.vercel.app](https://vercel.live/link/recnet-git-dev-recnet-542617e7.vercel.app)
recnet-api:
[https://dev-api.recnet.io/api](https://dev-api.recnet.io/api)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants