| 211 | } // namespace |
| 212 | |
| 213 | CesiumAsync::SharedFuture<CesiumIonAssetAccessor::UpdatedToken> |
| 214 | CesiumIonAssetAccessor::refreshTokenInMainThread( |
| 215 | const CesiumAsync::AsyncSystem& asyncSystem, |
| 216 | const std::string& currentAuthorizationHeaderValue, |
| 217 | const std::string& currentAccessTokenQueryParameterValue) { |
| 218 | if (this->_tokenRefreshInProgress) { |
| 219 | if (!this->_tokenRefreshInProgress->isReady()) { |
| 220 | // Still waiting for an in-progress token refresh. |
| 221 | return *this->_tokenRefreshInProgress; |
| 222 | } |
| 223 | |
| 224 | const UpdatedToken& refreshedToken = this->_tokenRefreshInProgress->wait(); |
| 225 | bool hasHeader = !currentAuthorizationHeaderValue.empty(); |
| 226 | bool hasParameter = !currentAccessTokenQueryParameterValue.empty(); |
| 227 | bool headerChanged = hasHeader && refreshedToken.authorizationHeader != |
| 228 | currentAuthorizationHeaderValue; |
| 229 | bool parameterChanged = |
| 230 | hasParameter && |
| 231 | refreshedToken.token != currentAccessTokenQueryParameterValue; |
| 232 | if (headerChanged || parameterChanged) { |
| 233 | // Only use this refreshed token if it's different from the one we're |
| 234 | // currently using. Otherwise, fall through and get a new token. |
| 235 | return *this->_tokenRefreshInProgress; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | SPDLOG_LOGGER_INFO( |
| 240 | this->_pLogger, |
| 241 | "Refreshing Cesium ion token for URL {}.", |
| 242 | this->_assetEndpointUrl); |
| 243 | |
| 244 | this->_tokenRefreshInProgress = |
| 245 | this->_pAggregatedAccessor |
| 246 | ->get( |
| 247 | asyncSystem, |
| 248 | this->_assetEndpointUrl, |
| 249 | this->_assetEndpointHeaders) |
| 250 | .thenInMainThread([this, asyncSystem]( |
| 251 | std::shared_ptr<CesiumAsync::IAssetRequest>&& |
| 252 | pIonRequest) { |
| 253 | if (!this->_maybeUpdatedTokenCallback) { |
| 254 | // Owner is already destroyed. |
| 255 | return asyncSystem.createResolvedFuture(UpdatedToken()); |
| 256 | } |
| 257 | |
| 258 | const CesiumAsync::IAssetResponse* pIonResponse = |
| 259 | pIonRequest->response(); |
| 260 | |
| 261 | if (!pIonResponse) { |
| 262 | // Token refresh failed. |
| 263 | SPDLOG_LOGGER_ERROR( |
| 264 | this->_pLogger, |
| 265 | "Request failed while attempting to refresh the Cesium " |
| 266 | "ion token."); |
| 267 | return asyncSystem.createResolvedFuture(UpdatedToken()); |
| 268 | } |
| 269 | |
| 270 | uint16_t statusCode = pIonResponse->statusCode(); |
no test coverage detected