| 925 | } |
| 926 | |
| 927 | CesiumAsync::Future<CesiumUtility::Result<std::string>> |
| 928 | Connection::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 |
no test coverage detected