MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / ensureValidToken

Method ensureValidToken

CesiumITwinClient/src/Connection.cpp:927–963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

925}
926
927CesiumAsync::Future<CesiumUtility::Result<std::string>>
928Connection::ensureValidToken() {
929 if (this->_authenticationToken.isValid()) {
930 return _asyncSystem.createResolvedFuture(
931 Result<std::string>(this->_authenticationToken.getTokenHeader()));
932 }
933
934 if (!this->_refreshToken) {
935 return _asyncSystem.createResolvedFuture(Result<std::string>(
936 ErrorList::error("No valid auth token or refresh token.")));
937 }
938
939 return CesiumClientCommon::OAuth2PKCE::refresh(
940 this->_asyncSystem,
941 this->_pAssetAccessor,
942 this->_clientOptions,
943 ITWIN_TOKEN_URL,
944 *this->_refreshToken)
945 .thenInMainThread(
946 [this](Result<CesiumClientCommon::OAuth2TokenResponse>&& response) {
947 if (!response.value) {
948 return Result<std::string>(response.errors);
949 }
950
951 Result<AuthenticationToken> tokenResult =
952 AuthenticationToken::parse(response.value->accessToken);
953 if (!tokenResult.value) {
954 return Result<std::string>(tokenResult.errors);
955 }
956
957 this->_authenticationToken = std::move(*tokenResult.value);
958 this->_refreshToken = std::move(response.value->refreshToken);
959
960 return Result<std::string>(
961 this->_authenticationToken.getTokenHeader());
962 });
963}
964
965} // namespace CesiumITwinClient

Callers 2

meMethod · 0.95
Connection.cppFile · 0.45

Calls 3

getTokenHeaderMethod · 0.80
isValidMethod · 0.45
thenInMainThreadMethod · 0.45

Tested by

no test coverage detected