modelcontextprotocol / modelcontextprotocol/typescript-sdk

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

Aperta
#830 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

auth enhancement needs decision P3
Lingua principale
TypeScript
Stelle
13.4k
Fork
2.2k
Merge medio
3g 15h
PR unite (30g)
4

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo l’handler OAuthServerProvider.authorize e l’esempio DemoInMemoryAuthProvider in src/examples/server/demoInMemoryOAuthProvider.ts, quindi segui come router.all() inoltra le richieste a /authorize. Definisci come devono essere esposti l’avvio del login tramite GET e la gestione successiva al consenso tramite POST, e verifica che entrambi i flussi ricevano il contesto della richiesta richiesto senza dipendere da res.req.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api, authentication, authorization
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.