Sam
06/14/2023, 6:38 PMinstall(Auth) {
bearer {
loadTokens {
// Load tokens from a local storage and return them as the 'BearerTokens' instance
BearerTokens("abc123", "xyz111")
}
}
}
The loadTokens
block is only called once, upon launch.
I'd like to do a local check for whether the JWT token has expired. Originally my plan was to do that check in the loadTokens
block but since it's only called once that won't work. is there any other way to do this? (Short of using the HttpSend
plugin to intercept requests and check the token)CLOVIS
06/15/2023, 7:55 AMbearer {
loadTokens {
// Initial token
}
refreshTokens {
// Generate new tokens
}
}
The idea is: when your token expires, the request will fail with 401 Unauthorized (if your server is written correctly). Ktor will notice that, execute the refreshTokens
function, and restart the request with the new token.CLOVIS
06/15/2023, 7:57 AMSam
06/15/2023, 9:44 AMCLOVIS
06/15/2023, 9:45 AMSam
06/15/2023, 9:47 AM