@@ -88,18 +88,22 @@ export function requireValidAccessToken() {
8888}
8989
9090/**
91- * Middleware to require specific OAuth2 scope
91+ * Middleware to require specific OAuth2 scope (only for OAuth2 Bearer token requests)
92+ * Skips validation for cookie-based authentication
9293 */
9394export function requireOAuthScope ( requiredScope : string ) {
9495 return async ( request : FastifyRequest , reply : FastifyReply ) => {
95- // This middleware should run after requireValidAccessToken
96+ // Skip scope check if user authenticated via cookie (not OAuth2)
9697 if ( ! request . tokenPayload ) {
97- const errorResponse = {
98- error : 'invalid_request' ,
99- error_description : 'OAuth2 token validation required before scope check'
100- } ;
101- const jsonString = JSON . stringify ( errorResponse ) ;
102- return reply . status ( 500 ) . type ( 'application/json' ) . send ( jsonString ) ;
98+ // User authenticated via cookie session - skip OAuth scope validation
99+ request . log . debug ( {
100+ operation : 'oauth_scope_check' ,
101+ userId : request . user ?. id ,
102+ requiredScope,
103+ authType : 'cookie' ,
104+ result : 'skipped'
105+ } , 'Skipping OAuth2 scope check for cookie-based authentication' ) ;
106+ return ; // Allow the request to continue
103107 }
104108
105109 const userScopes = request . tokenPayload . scope ;
@@ -131,18 +135,22 @@ export function requireOAuthScope(requiredScope: string) {
131135}
132136
133137/**
134- * Middleware to require any of the specified OAuth2 scopes
138+ * Middleware to require any of the specified OAuth2 scopes (only for OAuth2 Bearer token requests)
139+ * Skips validation for cookie-based authentication
135140 */
136141export function requireAnyOAuthScope ( requiredScopes : string [ ] ) {
137142 return async ( request : FastifyRequest , reply : FastifyReply ) => {
138- // This middleware should run after requireValidAccessToken
143+ // Skip scope check if user authenticated via cookie (not OAuth2)
139144 if ( ! request . tokenPayload ) {
140- const errorResponse = {
141- error : 'invalid_request' ,
142- error_description : 'OAuth2 token validation required before scope check'
143- } ;
144- const jsonString = JSON . stringify ( errorResponse ) ;
145- return reply . status ( 500 ) . type ( 'application/json' ) . send ( jsonString ) ;
145+ // User authenticated via cookie session - skip OAuth scope validation
146+ request . log . debug ( {
147+ operation : 'oauth_scope_check' ,
148+ userId : request . user ?. id ,
149+ requiredScopes,
150+ authType : 'cookie' ,
151+ result : 'skipped'
152+ } , 'Skipping OAuth2 scope check for cookie-based authentication' ) ;
153+ return ; // Allow the request to continue
146154 }
147155
148156 const userScopes = request . tokenPayload . scope ;
0 commit comments