I access a REST API that rely on a temporary token. The token is short lived, but does come with a refresh token. I store it in a struct like
mutable struct MyToken
AccessToken::String
RefreshToken::String
ExpiresIn::UInt64
end
I have a method refresh!(token)
that updates AccessToken
using RefreshToken
.
I would like to keep the token valid throughout the lifetime of my Julia session. Something like this works
function auto_refresh!(token)
@async begin
sleep(token.ExpiresIn)
@info "Updating token"
refresh!(token)
auto_refresh!(token)
end
end
But I wonder if this is a good approach?