modelcontextprotocol / modelcontextprotocol/typescript-sdk

Need to handle GET and POST differently in OAuthServerProvider.authorize handler

Open
#830 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auth enhancement needs decision P3
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Problem

The current OAuthServerProvider.authorize method is called for both GET and POST requests to /authorize, but I need to handle them differently:

  • GET /authorize - Should start the user login process
  • POST /authorize - Should handle the result after the user has logged in and consented

Current Situation

The authorization handler uses router.all(), so the same authorize() method gets called for both HTTP methods. I can't tell which one it is without accessing the request object through res.req.method.

Use Case

I'm building an OAuth server where users need to log in first (via SSO, SAML, etc.) before they can consent to authorization. This requires different handling for GET vs POST requests.

Current Workaround

async authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response) {
  const req = (res as any).req as Request;
  
  if (req.method === 'GET') {
    // Start login flow
  } else if (req.method === 'POST') {
    // Handle post-login authorization
  }
}

The existing DemoInMemoryAuthProvider example is very simple and immediately generates an authorization code without any user login flow - it's just for demonstration purposes. Real-world OAuth servers need to handle user authentication before authorization.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the OAuthServerProvider.authorize handler and the DemoInMemoryAuthProvider example in src/examples/server/demoInMemoryOAuthProvider.ts, then trace how router.all() dispatches /authorize requests. Define how GET login initiation and POST post-consent handling should be exposed, and verify that both flows receive the required request context without relying on res.req.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, authentication, authorization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.