Conversation
I'm a little confused. Why does a slack bot need to authenticate users when it can just authenticate itself (even just using the existing login endpoints) and then call the endpoints it needs to on behalf of the user? We could then just record what userId the slackbot is inside the .env file and then add a new guard that limits the slack bot to only call just the /ask endpoint (and maybe any other endpoints it needs but I think /ask is all it needs). Granted, this would mean you wouldn't have any user tracking. For that you would need to create new users here based on the slack user's information (which this PR doesn't seem to do and only seems to authenticate existing users?) and then store a map (either on HelpMe DB or on the slackbot itself) that maps each userId to slack user and then essentially call the /ask endpoint on behalf of said user (or something like that, anyway). And while user tracking would be nice, it would require a lot more work and thought to do securely. |
Actually this part may not be as simple since there's different courses. Though, I guess the slackbot can just be invited to all courses that require it, and then it decide what courses' /ask endpoint should be called based on what channel the person asked the question in (or something like that) |
Description
This PR implements Slack account linking functionality for HelpMe, enabling Slack bots to authenticate users and access HelpMe's chatbot through a secure OAuth 2.0 flow. The feature provides a complete account binding system that allows Slack users to link their HelpMe accounts and access course-specific chatbot functionality.
Key Features:
Motivation: Slack bots need a secure way to authenticate users and access HelpMe's chatbot API. This implementation provides a standard OAuth flow that allows Slack applications to link user accounts and retrieve necessary data for chatbot interactions, course management, and user-specific functionality.
Dependencies: None - uses existing auth system and database infrastructure.
Type of change
yarn installHow Has This Been Tested?
Please describe how you tested this PR (both manually and with tests)
Provide instructions so we can reproduce.
/linkcommand to successful account bindingReproduction Steps:
/linkcommand pointing to HelpMe OAuth endpoints/linkin Slack and follow OAuth flowChecklist:
Files Changed
New Files:
packages/server/src/slack/slack-link-code.entity.ts- Database entity for temporary linking codesModified Files:
packages/server/src/auth/auth.service.ts- Added Slack linking methodspackages/server/src/auth/auth.controller.ts- Added OAuth endpointspackages/server/ormconfig.ts- Registered new entityAPI Endpoints Added
GET /api/v1/auth/slack/start- OAuth entry pointGET /api/v1/auth/slack/finish- Code generation and redirectPOST /api/v1/auth/slack/exchange- Server-to-server code exchangeData Structure
Returns user data in format:
{ "userId": 123, "name": "John Doe", "email": "john@example.com", "organizationId": 1, "courses": [ {"id": 1, "name": "CS 101"}, {"id": 2, "name": "Math 200"} ], "chatToken": "uuid-for-chatbot-api" }