You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Add RFC 6750 Bearer Token Authentication Support
This PR implements RFC 6750 Bearer Token authentication as an additional authentication method for Coder's API. This allows clients to authenticate using standard OAuth 2.0 Bearer tokens in two ways:
1. Using the `Authorization: Bearer <token>` header
2. Using the `access_token` query parameter
Key changes:
- Added support for extracting tokens from both Bearer headers and access_token query parameters
- Implemented proper WWW-Authenticate headers for 401/403 responses with appropriate error descriptions
- Added comprehensive test coverage for the new authentication methods
- Updated the OAuth2 protected resource metadata endpoint to advertise Bearer token support
- Enhanced the OAuth2 testing script to verify Bearer token functionality
These authentication methods are added as fallback options, maintaining backward compatibility with Coder's existing authentication mechanisms. The existing authentication methods (cookies, session token header, etc.) still take precedence.
This implementation follows the OAuth 2.0 Bearer Token specification (RFC 6750) and improves interoperability with standard OAuth 2.0 clients.
wwwAuth=`Bearer realm="coder", error="invalid_token", error_description="The access token audience does not match this resource"`
229
+
default:
230
+
wwwAuth=`Bearer realm="coder", error="invalid_token", error_description="The access token is invalid"`
231
+
}
232
+
casehttp.StatusForbidden:
233
+
// Map 403 to insufficient_scope per RFC 6750
234
+
wwwAuth=`Bearer realm="coder", error="insufficient_scope", error_description="The request requires higher privileges than provided by the access token"`
235
+
default:
236
+
wwwAuth=`Bearer realm="coder"`
237
+
}
238
+
239
+
rw.Header().Set("WWW-Authenticate", wwwAuth)
240
+
}
241
+
217
242
httpapi.Write(ctx, rw, code, response)
218
243
returnnil, nil, false
219
244
}
@@ -653,9 +678,14 @@ func UserRBACSubject(ctx context.Context, db database.Store, userID uuid.UUID, s
653
678
// 1: The cookie
654
679
// 2. The coder_session_token query parameter
655
680
// 3. The custom auth header
681
+
// 4. RFC 6750 Authorization: Bearer header
682
+
// 5. RFC 6750 access_token query parameter
656
683
//
657
684
// API tokens for apps are read from workspaceapps/cookies.go.
658
685
funcAPITokenFromRequest(r*http.Request) string {
686
+
// Prioritize existing Coder custom authentication methods first
687
+
// to maintain backward compatibility and existing behavior
0 commit comments