Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfca6b9a

Browse files
committed
feat(oauth2): implement RFC 6750 Bearer Token Support for MCP compliance
- Add RFC 6750 bearer token extraction to APITokenFromRequest as fallback methods- Support Authorization: Bearer <token> header and access_token query parameter- Maintain backward compatibility by prioritizing existing custom methods first- Add WWW-Authenticate headers to 401/403 responses per RFC 6750- Update Protected Resource Metadata to advertise bearer_methods_supported- Add comprehensive test suite for RFC 6750 compliance in rfc6750_test.go- Update MCP test scripts with bearer token authentication tests- Enhance CLAUDE.md with improved Go LSP tool usage guidelinesImplements RFC 6750 Section 2.1 (Authorization Request Header Field) and 2.3 (URI Query Parameter).Maintains full backward compatibility with existing Coder authentication methods.Completes major MCP OAuth2 compliance milestone.Change-Id: Ic9c9057153b40728ad91b377d753a7ffd566add7Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parentfded148 commitfca6b9a

File tree

6 files changed

+983
-7
lines changed

6 files changed

+983
-7
lines changed

‎coderd/httpmw/apikey.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
209209
returnnil,nil,false
210210
}
211211

212+
// Add WWW-Authenticate header for 401/403 responses (RFC 6750)
213+
ifcode==http.StatusUnauthorized||code==http.StatusForbidden {
214+
// Basic Bearer challenge with realm
215+
wwwAuth:=`Bearer realm="coder"`
216+
217+
// Add error details based on the type of error
218+
switch {
219+
casestrings.Contains(response.Message,"invalid")||strings.Contains(response.Detail,"invalid"):
220+
wwwAuth=`Bearer realm="coder", error="invalid_token", error_description="The access token is invalid"`
221+
casestrings.Contains(response.Message,"expired")||strings.Contains(response.Detail,"expired"):
222+
wwwAuth=`Bearer realm="coder", error="invalid_token", error_description="The access token has expired"`
223+
casestrings.Contains(response.Message,"audience")||strings.Contains(response.Message,"mismatch"):
224+
wwwAuth=`Bearer realm="coder", error="invalid_token", error_description="The access token audience does not match this resource"`
225+
casecode==http.StatusForbidden:
226+
wwwAuth=`Bearer realm="coder", error="insufficient_scope", error_description="The request requires higher privileges than provided by the access token"`
227+
}
228+
229+
rw.Header().Set("WWW-Authenticate",wwwAuth)
230+
}
231+
212232
httpapi.Write(ctx,rw,code,response)
213233
returnnil,nil,false
214234
}
@@ -534,9 +554,14 @@ func UserRBACSubject(ctx context.Context, db database.Store, userID uuid.UUID, s
534554
// 1: The cookie
535555
// 2. The coder_session_token query parameter
536556
// 3. The custom auth header
557+
// 4. RFC 6750 Authorization: Bearer header
558+
// 5. RFC 6750 access_token query parameter
537559
//
538560
// API tokens for apps are read from workspaceapps/cookies.go.
539561
funcAPITokenFromRequest(r*http.Request)string {
562+
// Prioritize existing Coder custom authentication methods first
563+
// to maintain backward compatibility and existing behavior
564+
540565
cookie,err:=r.Cookie(codersdk.SessionTokenCookie)
541566
iferr==nil&&cookie.Value!="" {
542567
returncookie.Value
@@ -552,7 +577,18 @@ func APITokenFromRequest(r *http.Request) string {
552577
returnheaderValue
553578
}
554579

555-
// TODO(ThomasK33): Implement RFC 6750
580+
// RFC 6750 Bearer Token support (added as fallback methods)
581+
// Check Authorization: Bearer <token> header
582+
authHeader:=r.Header.Get("Authorization")
583+
ifstrings.HasPrefix(authHeader,"Bearer ") {
584+
returnstrings.TrimPrefix(authHeader,"Bearer ")
585+
}
586+
587+
// Check access_token query parameter
588+
accessToken:=r.URL.Query().Get("access_token")
589+
ifaccessToken!="" {
590+
returnaccessToken
591+
}
556592

557593
return""
558594
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp