#pragma once #include #include #include #include #include #include #include #include namespace CesiumAsync { /** * @brief An \ref IAssetAccessor that wraps another one and handles Cesium ion * token refresh when an asset returns a 401 error. * * It's rarely necessary to use this class directly. It's created by \ref * Cesium3DTilesSelection::CesiumIonTilesetContentLoaderFactory and \ref * CesiumRasterOverlays::IonRasterOverlay as needed. */ class CesiumIonAssetAccessor : public std::enable_shared_from_this, public IAssetAccessor { public: /** * @brief The details of the updated token. */ struct UpdatedToken { /** * @brief The new token. */ std::string token; /** * @brief The new Authorization header containing the new token. */ std::string authorizationHeader; }; /** * @brief Creates a new instance. */ CesiumIonAssetAccessor( const std::shared_ptr& pLogger, const std::shared_ptr& pAggregatedAccessor, const std::string& assetEndpointUrl, const std::vector& assetEndpointHeaders, std::function(const UpdatedToken&)> updatedTokenCallback); /** * \inheritdoc */ Future> get(const AsyncSystem& asyncSystem, const std::string& url, const std::vector& headers = {}) override; /** * \inheritdoc */ Future> request( const AsyncSystem& asyncSystem, const std::string& verb, const std::string& url, const std::vector& headers = std::vector(), const std::span& contentPayload = {}) override; /** * \inheritdoc */ void tick() noexcept override; /** * @brief Notifies this accessor that it's owner has been destroyed. When the * owner is destroyed, the token will no longer be refreshed. */ void notifyOwnerIsBeingDestroyed(); private: SharedFuture refreshTokenInMainThread( const AsyncSystem& asyncSystem, const std::string& currentAuthorizationHeader, const std::string& currentAccessTokenQueryParameterValue); std::shared_ptr _pLogger; std::shared_ptr _pAggregatedAccessor; std::string _assetEndpointUrl; std::vector _assetEndpointHeaders; std::optional(const UpdatedToken&)>> _maybeUpdatedTokenCallback; std::optional> _tokenRefreshInProgress; }; } // namespace CesiumAsync