Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions handlers/Jwt.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ component extends="coldbox.system.RestHandler" {
function refreshToken( event, rc, prc ){
// If endpoint not enabled, just 404 it
if ( !variables.jwtService.getSettings().jwt.enableRefreshEndpoint ) {
return event
event
.getResponse()
.setErrorMessage(
"Refresh Token Endpoint Disabled",
404,
"Disabled"
);
return;
}

try {
Expand All @@ -32,27 +33,31 @@ component extends="coldbox.system.RestHandler" {
.setData( prc.newTokens )
.addMessage( "Tokens refreshed! The passed in refresh token has been invalidated" );
} catch ( RefreshTokensNotActive e ) {
return event.getResponse().setErrorMessage( "Refresh Tokens Not Active", 404, "Disabled" );
event.getResponse().setErrorMessage( "Refresh Tokens Not Active", 404, "Disabled" );
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing explicit return; statement for consistency. Line 24 includes an explicit return; after setting the error message. For consistency across all error paths in this function, consider adding return; here as well.

Copilot uses AI. Check for mistakes.
} catch ( TokenNotFoundException e ) {
return event
event
.getResponse()
.setErrorMessage(
"The refresh token was not passed via the header or the rc. Cannot refresh the unrefreshable!",
400,
"Missing refresh token"
);
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing explicit return; statement for consistency. Line 24 includes an explicit return; after setting the error message. For consistency across all error paths in this function, consider adding return; after line 44.

Suggested change
);
);
return;

Copilot uses AI. Check for mistakes.
} catch ( TokenInvalidException e ) {
prc.response.setErrorMessage(
"Invalid Token - #e.message#",
401,
"Invalid Token"
);
event
.getResponse()
.setErrorMessage(
"Invalid Token - #e.message#",
401,
"Invalid Token"
);
Comment on lines +46 to +52
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing explicit return; statement for consistency. Line 24 includes an explicit return; after setting the error message. For consistency across all error paths in this function, consider adding return; after line 52.

Copilot uses AI. Check for mistakes.
} catch ( TokenExpiredException e ) {
prc.response.setErrorMessage(
"Token Expired - #e.message#",
400,
"Token Expired"
);
event
.getResponse()
.setErrorMessage(
"Token Expired - #e.message#",
400,
"Token Expired"
);
Comment on lines +54 to +60
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing explicit return; statement for consistency. Line 24 includes an explicit return; after setting the error message. For consistency across all error paths in this function, consider adding return; after line 60.

Copilot uses AI. Check for mistakes.
}
}

Expand Down
9 changes: 9 additions & 0 deletions test-harness/tests/specs/integration/JWTSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
404,
event.getResponse().getMessagesString()
);

// Matches the ColdBox RestHandler default response format spec
var jsonResponse = deserializeJSON( event.getRenderedContent() );
expect( jsonResponse ).toHaveLength( 4 );
expect( jsonResponse ).toHaveKey( "data" );
expect( jsonResponse ).toHaveKey( "error" );
expect( jsonResponse ).toHaveKey( "pagination" );
expect( jsonResponse ).toHaveKey( "messages" );
expect( jsonResponse.messages[ 1 ] ).toBe( event.getResponse().getMessagesString() );
} );
} );
given( "An activated endpoint but no refresh tokens passed", function(){
Expand Down
Loading