#pragma once // Spec: models.md AuthToken. Wire: token_type, access_token, expires_in (seconds). expireTime = now + expires_in // at decode time. willExpireSoon: (expireTime - now) < 3600 s, strict; an expired token is also "soon". #include #include #include "core/Date.hpp" #include "core/Json.hpp" namespace dp { struct AuthToken { std::string tokenType; std::string accessToken; Date expireTime{}; static AuthToken fromJson(const Json& j) { return fromJson(j, DateCodec::now()); } static AuthToken fromJson(const Json& j, Date now); bool isExpired() const { return isExpired(DateCodec::now()); } bool isExpired(Date now) const { return expireTime < now; } bool willExpireSoon() const { return willExpireSoon(DateCodec::now()); } bool willExpireSoon(Date now) const; }; } // namespace dp