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

Tolga ÇAĞLAYAN

03/20/2023, 5:43 PM
Copy code
fun isTokenBlacklistedAdmin(token: Payload): Boolean {
    val fetch =  transaction {
        AdminTokenTable.select {
            AdminTokenTable.token eq token.toString()
        }.firstOrNull()?.let {
            AdminTokenList(
                token = it[AdminTokenTable.token],
                blackList = it[AdminTokenTable.blackList]
            )
        }
    }
    return when (
       fetch?.blackList
    ) {
        1 -> {

            true
        }

        0 -> {
            println("0")
            false
        }

        else -> {
            true
        }
    }
}
I have such a code block. While performing JWT validation, I want to check from the database whether the token is blacklisted. But how can I read the token from Payload? token.toString() doesn't work. I couldn't find any detailed information.
b

Berkay Özkan

03/20/2023, 5:56 PM
You can get from header if you need token directly or you can add claim to jwt (some hashcode maybe) and store that hashcode in db and check if that hashcode is in blacklist. This way it will be more secure i think
t

Tolga ÇAĞLAYAN

03/20/2023, 6:14 PM
I created JWT id with UUID. Save it to database. I verified with JWT id. It is working now. Thanks
🙌 1
5 Views