spacebarchat / spacebarchat/server
Update Multi-Factor Authentication routes to work with new clients
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.2k
- Forks
- 323
- Avg merge
- 14h 48m
- Merged PRs (30d)
- 4
Description
Enabling MFA (POST /api/v9/users/@me/mfa/totp/enable):
Request:
{"code":"123456","secret":"2fa-secret"}
Response:
{
"message": "Two factor is required for this operation",
"code": 60003,
"mfa": {
"ticket": "totp-ticket",
"methods": [{ "type": "password" }]
}
}
This is referenced also in https://github.com/spacebarchat/server/issues/1314#issuecomment-3082044103
The response returns a new cookie called __Secure-recent_mfa which is empty.
Then a request is sent to POST /api/v9/mfa/finish.
Request:
{
"ticket": "totp-ticket",
"mfa_type": "password",
"data": "password or 2fa code"
}
Response:
{"token":"finish-token"}
Then a final request is sent to POST /api/v9/users/@me/mfa/totp/enable with the cookie __Secure-recent_mfa containing the /api/v9/mfa/finish response token (bypasses MFA for 5 minutes), along with the X-Discord-MFA-Authorization header, also containing that token.
Request:
{ "code": "123456", "secret": "2fa-secret" }
Response:
{
"token": "token2",
"backup_codes": [
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false },
{ "user_id": "snowflake", "code": "abcdabcd", "consumed": false }
]
}
If you need to find out more about the flow, there's a page on Userdoccers:
https://docs.discord.food/authentication#login-account - contains the authentication flow too
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the POST /api/v9/users/@me/mfa/totp/enable and POST /api/v9/mfa/finish entry points, then compare their current behavior with the request and response flow described here. Verify the MFA ticket, finish token, __Secure-recent_mfa cookie, X-Discord-MFA-Authorization header, and backup_codes response for the final enable request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100