9
9
InvalidRequestError ,
10
10
ServerError ,
11
11
TooManyRequestsError ,
12
- OAuthError
12
+ OAuthError ,
13
13
} from "../errors.js" ;
14
14
15
15
export type RevocationHandlerOptions = {
@@ -21,7 +21,10 @@ export type RevocationHandlerOptions = {
21
21
rateLimit ?: Partial < RateLimitOptions > | false ;
22
22
} ;
23
23
24
- export function revocationHandler ( { provider, rateLimit : rateLimitConfig } : RevocationHandlerOptions ) : RequestHandler {
24
+ export function revocationHandler ( {
25
+ provider,
26
+ rateLimit : rateLimitConfig ,
27
+ } : RevocationHandlerOptions ) : RequestHandler {
25
28
if ( ! provider . revokeToken ) {
26
29
throw new Error ( "Auth provider does not support revoking tokens" ) ;
27
30
}
@@ -37,21 +40,25 @@ export function revocationHandler({ provider, rateLimit: rateLimitConfig }: Revo
37
40
38
41
// Apply rate limiting unless explicitly disabled
39
42
if ( rateLimitConfig !== false ) {
40
- router . use ( rateLimit ( {
41
- windowMs : 15 * 60 * 1000 , // 15 minutes
42
- max : 50 , // 50 requests per windowMs
43
- standardHeaders : true ,
44
- legacyHeaders : false ,
45
- message : new TooManyRequestsError ( 'You have exceeded the rate limit for token revocation requests' ) . toResponseObject ( ) ,
46
- ...rateLimitConfig
47
- } ) ) ;
43
+ router . use (
44
+ rateLimit ( {
45
+ windowMs : 15 * 60 * 1000 , // 15 minutes
46
+ max : 50 , // 50 requests per windowMs
47
+ standardHeaders : true ,
48
+ legacyHeaders : false ,
49
+ message : new TooManyRequestsError (
50
+ "You have exceeded the rate limit for token revocation requests"
51
+ ) . toResponseObject ( ) ,
52
+ ...rateLimitConfig ,
53
+ } )
54
+ ) ;
48
55
}
49
56
50
57
// Authenticate and extract client details
51
58
router . use ( authenticateClient ( { clientsStore : provider . clientsStore } ) ) ;
52
59
53
60
router . post ( "/" , async ( req , res ) => {
54
- res . setHeader ( ' Cache-Control' , ' no-store' ) ;
61
+ res . setHeader ( " Cache-Control" , " no-store" ) ;
55
62
56
63
try {
57
64
const parseResult = OAuthTokenRevocationRequestSchema . safeParse ( req . body ) ;
@@ -62,7 +69,6 @@ export function revocationHandler({ provider, rateLimit: rateLimitConfig }: Revo
62
69
const client = req . client ;
63
70
if ( ! client ) {
64
71
// This should never happen
65
- console . error ( "Missing client information after authentication" ) ;
66
72
throw new ServerError ( "Internal Server Error" ) ;
67
73
}
68
74
@@ -73,7 +79,6 @@ export function revocationHandler({ provider, rateLimit: rateLimitConfig }: Revo
73
79
const status = error instanceof ServerError ? 500 : 400 ;
74
80
res . status ( status ) . json ( error . toResponseObject ( ) ) ;
75
81
} else {
76
- console . error ( "Unexpected error revoking token:" , error ) ;
77
82
const serverError = new ServerError ( "Internal Server Error" ) ;
78
83
res . status ( 500 ) . json ( serverError . toResponseObject ( ) ) ;
79
84
}
0 commit comments