https://kotlinlang.org logo
#ktor
Title
# ktor
a

Ahmed Riyadh

03/28/2024, 12:48 PM
When using Ktor Server authentication plugin with JWT, and use it to protect routes, when the token expire it will throw this exception:
Copy code
com.auth0.jwt.exceptions.TokenExpiredException: The Token has expired on 2024-03-28T12:11:25Z.
	at com.auth0.jwt.JWTVerifier$BaseVerification.assertValidInstantClaim(JWTVerifier.java:346)
	at com.auth0.jwt.JWTVerifier$BaseVerification.lambda$addMandatoryClaimChecks$17(JWTVerifier.java:308)
	at com.auth0.jwt.JWTVerifier$BaseVerification$1.verify(JWTVerifier.java:405)
	at com.auth0.jwt.JWTVerifier.verifyClaims(JWTVerifier.java:482)
	at com.auth0.jwt.JWTVerifier.verify(JWTVerifier.java:464)
	at com.auth0.jwt.JWTVerifier.verify(JWTVerifier.java:445)
	at io.ktor.server.auth.jwt.JWTUtilsKt.verifyAndValidate(JWTUtils.kt:95)
Is there a way to not print this exception to the log? I tried using StatusPages Plugin to handle the exception but it didn't work (Maybe this is just a message that is being printed) + even if it works it will not when using WebSockets because StatusPages plugin doesn't support Web Sockets
a

Aleksei Tirman [JB]

03/28/2024, 4:21 PM
So the only problem is that the stack trace pollutes the log?
a

Ahmed Riyadh

03/28/2024, 4:34 PM
Yes
a

Aleksei Tirman [JB]

03/28/2024, 6:18 PM
I think you can solve the problem by configuring the logger to exclude the
TokenExpiredException
from the logs.
a

Ahmed Riyadh

03/29/2024, 12:22 PM
Any idea how?
a

Aleksei Tirman [JB]

03/29/2024, 12:49 PM
What logger provider do you use?
a

Ahmed Riyadh

03/29/2024, 12:50 PM
The ktor server default logger (logback classic)
a

Aleksei Tirman [JB]

03/29/2024, 1:10 PM
You can find an answer here.
👍 1
2 Views