You need to use a refresh token. OAuth gives you an initial token to use to authenticate and a refresh token assuming you're using a standard client credential grant type (which services to services tend to use). When the original auth token expires you can contact the OAuth server again and pass it the refresh token to get an updated token that you can then continue to use until it expires. In my experience OAuth servers can return refresh tokens indefinitely so you only need to "log in" once but it depends on the implementation. As part of the original auth request it also tells you how long the token is good for.
Alternatively you could also probably just call the az login
(or whatever that command is) when the token expires to log in again anyway.