Skip to content

[BUG] OAuth Connect Callback Blocked by Header-Only Authentication Check #380

@Pcmhacker-piro

Description

@Pcmhacker-piro

Summary

Refactor the third-party account linkage callback endpoint (/api/connect/github/callback) to verify user identity via a Redis state nonce instead of a direct HTTP header authentication check. This allows browser-level GET redirects from GitHub to authenticate without throwing a 401.

Contexts

In apps/backend/src/routes/connect.ts, the GET endpoint /github/callback is decorated with preHandler: [app.authenticate].

Because OAuth redirects are browser-initiated GET page loads, the user's browser redirects from github.com straight to /api/connect/github/callback?code=...&state=.... The client cannot programmatically inject an Authorization: Bearer <token> header into this browser-level redirect. Since fastify-jwt is registered in app.ts without any cookie extraction support, the request.jwtVerify() call in app.authenticate fails to find a token and immediately terminates the callback flow with a 401 Unauthorized error.

Tasks

  • Remove preHandler: [app.authenticate] from /github/callback in apps/backend/src/routes/connect.ts.
  • Extract the target user's identity by decoding the state parameter redirect value.
  • Verify the temporary nonce received in the callback against the Redis store to retrieve the matching userId.
  • Delete the token from Redis after validation to prevent replay attacks (one-time use).
  • Use the validated userId to create or update the corresponding oAuthToken in PostgreSQL.

Acceptance Criteria

  • Third-party account linking via GitHub completes successfully without 401 Unauthorized errors.
  • Callback security remains intact via Redis-backed state-nonce validation.
  • The oAuthToken is correctly updated or created under the correct authenticated user.

Area

backend

Difficulty

Hard

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions