cesium-native 0.56.0
Loading...
Searching...
No Matches
Connection.h
1#pragma once
2
3#include <CesiumAsync/AsyncSystem.h>
4#include <CesiumAsync/IAssetAccessor.h>
5#include <CesiumAsync/Library.h>
6#include <CesiumAsync/SharedFuture.h>
7#include <CesiumClientCommon/OAuth2PKCE.h>
8#include <CesiumIonClient/ApplicationData.h>
9#include <CesiumIonClient/Assets.h>
10#include <CesiumIonClient/Defaults.h>
11#include <CesiumIonClient/Geocoder.h>
12#include <CesiumIonClient/LoginToken.h>
13#include <CesiumIonClient/Profile.h>
14#include <CesiumIonClient/Response.h>
15#include <CesiumIonClient/Token.h>
16#include <CesiumIonClient/TokenList.h>
17#include <CesiumUtility/Result.h>
18
19#include <cstdint>
20#include <mutex>
21#include <optional>
22#include <string>
23
24namespace CesiumIonClient {
25
29enum class SortOrder { Ascending, Descending };
30
42 std::optional<int32_t> limit;
43
47 std::optional<int32_t> page;
48
54 std::optional<std::string> search;
55
60 std::optional<std::string> sortBy;
61
66 std::optional<SortOrder> sortOrder;
67};
68
73class CESIUMASYNC_API Connection {
74public:
111 const CesiumAsync::AsyncSystem& asyncSystem,
112 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
113 const std::string& friendlyApplicationName,
114 int64_t clientID,
115 const std::string& redirectPath,
116 const std::vector<std::string>& scopes,
117 std::function<void(const std::string&)>&& openUrlCallback,
119 const std::string& ionApiUrl = "https://api.cesium.com/",
120 const std::string& ionAuthorizeUrl = "https://ion.cesium.com/oauth");
121
132 const CesiumAsync::AsyncSystem& asyncSystem,
133 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
134 const std::string& apiUrl = "https://api.cesium.com");
135
153 const CesiumAsync::AsyncSystem& asyncSystem,
154 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
155 const std::string& ionUrl);
156
172 const CesiumAsync::AsyncSystem& asyncSystem,
173 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
174 const std::string& accessToken,
176 const std::string& apiUrl = "https://api.cesium.com");
177
201 const CesiumAsync::AsyncSystem& asyncSystem,
202 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
203 const CesiumIonClient::LoginToken& accessToken,
204 const std::string& refreshToken,
205 int64_t clientId,
206 const std::string& redirectPath,
208 const std::string& apiUrl = "https://api.cesium.com");
209
223 const CesiumAsync::AsyncSystem& asyncSystem,
224 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
226 const std::string& apiUrl);
227
232
237 const std::shared_ptr<CesiumAsync::IAssetAccessor>&
238 getAssetAccessor() const noexcept;
239
243 const std::string& getAccessToken() const noexcept;
244
248 const std::string& getRefreshToken() const noexcept;
249
253 const std::string& getApiUrl() const noexcept;
254
264 CesiumAsync::Future<Response<Profile>> me() const;
265
276
283
295 tokens(const ListTokensOptions& options = {}) const;
296
304
311 CesiumAsync::Future<Response<Token>> token(const std::string& tokenID) const;
312
324 nextPage(const Response<TokenList>& currentPage) const;
325
337 previousPage(const Response<TokenList>& currentPage) const;
338
351 const std::string& name,
352 const std::vector<std::string>& scopes,
353 const std::optional<std::vector<int64_t>>& assetIds = std::nullopt,
354 const std::optional<std::vector<std::string>>& allowedUrls =
355 std::nullopt) const;
356
371 const std::string& tokenID,
372 const std::string& newName,
373 const std::optional<std::vector<int64_t>>& newAssetIDs,
374 const std::vector<std::string>& newScopes,
375 const std::optional<std::vector<std::string>>& newAllowedUrls) const;
376
388 GeocoderProviderType provider,
390 const std::string& query) const;
391
399 static std::optional<std::string> getIdFromToken(const std::string& token);
400
401private:
402 // This is a separate structure so that it can outlive the Connection while an
403 // async operation is in progress.
404 struct TokenDetails {
405 TokenDetails(
406 const CesiumIonClient::LoginToken& accessToken,
407 const std::string& refreshToken);
408
409 CesiumIonClient::LoginToken accessToken;
410 std::string refreshToken;
411 std::optional<CesiumAsync::SharedFuture<CesiumUtility::Result<std::string>>>
412 refreshInProgress;
413 std::mutex mutex;
414 };
415
416 CesiumAsync::Future<Response<TokenList>> tokens(const std::string& url) const;
418 ensureValidToken() const;
419
420 CesiumAsync::AsyncSystem _asyncSystem;
421 std::shared_ptr<CesiumAsync::IAssetAccessor> _pAssetAccessor;
422 std::string _apiUrl;
424 int64_t _clientId;
425 std::string _redirectPath;
426 std::shared_ptr<TokenDetails> _pTokenDetails;
427};
428} // namespace CesiumIonClient
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition Future.h:29
CesiumAsync::Future< Response< TokenList > > tokens(const ListTokensOptions &options={}) const
Invokes the "List tokens" service to get the list of available tokens.
static CesiumAsync::Future< std::optional< std::string > > getApiUrl(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &ionUrl)
Attempts to retrieve the ion endpoint URL by looking for a config.json file on the server.
CesiumAsync::Future< Response< Profile > > me() const
Retrieves profile information for the access token currently being used to make API calls.
Connection(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &accessToken, const CesiumIonClient::ApplicationData &appData, const std::string &apiUrl="https://api.cesium.com")
Creates a connection to Cesium ion using the provided access token.
CesiumAsync::Future< Response< GeocoderResult > > geocode(GeocoderProviderType provider, GeocoderRequestType type, const std::string &query) const
Makes a request to the ion geocoding service.
CesiumAsync::Future< Response< Defaults > > defaults() const
Retrieves default imagery, terrain and building assets along with quick add assets that can be useful...
Connection(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const CesiumIonClient::ApplicationData &appData, const std::string &apiUrl)
Creates a connection to a Cesium ion server without authentication.
CesiumAsync::Future< Response< NoValue > > modifyToken(const std::string &tokenID, const std::string &newName, const std::optional< std::vector< int64_t > > &newAssetIDs, const std::vector< std::string > &newScopes, const std::optional< std::vector< std::string > > &newAllowedUrls) const
Modifies a token.
CesiumAsync::Future< Response< TokenList > > nextPage(const Response< TokenList > &currentPage) const
Gets the next page of results from the "List tokens" service.
CesiumAsync::Future< Response< Assets > > assets() const
Gets the list of available assets.
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Gets the async system used by this connection to do work in threads.
Connection(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const CesiumIonClient::LoginToken &accessToken, const std::string &refreshToken, int64_t clientId, const std::string &redirectPath, const CesiumIonClient::ApplicationData &appData, const std::string &apiUrl="https://api.cesium.com")
Creates a "login" connection to Cesium ion.
static std::optional< std::string > getIdFromToken(const std::string &token)
Decodes a token ID from a token.
const std::string & getAccessToken() const noexcept
Gets the access token used by this connection.
static CesiumAsync::Future< CesiumUtility::Result< Connection > > authorize(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &friendlyApplicationName, int64_t clientID, const std::string &redirectPath, const std::vector< std::string > &scopes, std::function< void(const std::string &)> &&openUrlCallback, const CesiumIonClient::ApplicationData &appData, const std::string &ionApiUrl="https://api.cesium.com/", const std::string &ionAuthorizeUrl="https://ion.cesium.com/oauth")
Authorizes access to Cesium ion on behalf of a user, and returns a Connection that can be used to int...
CesiumAsync::Future< Response< Token > > token(const std::string &tokenID) const
Gets details of the token with the given ID.
const std::shared_ptr< CesiumAsync::IAssetAccessor > & getAssetAccessor() const noexcept
Gets the interface used by this connection to interact with the Cesium ion REST API.
CesiumAsync::Future< Response< TokenList > > previousPage(const Response< TokenList > &currentPage) const
Gets the previous page of results from the "List tokens" service.
CesiumAsync::Future< Response< Token > > createToken(const std::string &name, const std::vector< std::string > &scopes, const std::optional< std::vector< int64_t > > &assetIds=std::nullopt, const std::optional< std::vector< std::string > > &allowedUrls=std::nullopt) const
Creates a new token.
const std::string & getRefreshToken() const noexcept
Gets the refresh token used by this connection.
static CesiumAsync::Future< Response< ApplicationData > > appData(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &apiUrl="https://api.cesium.com")
Retrieves information about the ion API server.
CesiumAsync::Future< Response< Asset > > asset(int64_t assetID) const
Gets details of the asset with the given ID.
A login token for interacting with the Cesium ion REST API, obtained from the OAuth authentication fl...
Definition LoginToken.h:21
Classes that support asynchronous operations.
Classes for working with Cesium ion clients.
GeocoderProviderType
The supported providers that can be accessed through ion's geocoder API.
Definition Geocoder.h:34
SortOrder
Whether sorted results should be ascending or descending.
Definition Connection.h:29
GeocoderRequestType
The supported types of requests to geocoding API.
Definition Geocoder.h:16
STL namespace.
Data retrieved from the Cesium ion server via an "appData" request from Cesium ion....
A page of assets obtained from the Cesium ion v1/assets endpoint, including a link to obtain the next...
Definition Assets.h:77
The data returned by Cesium ion's v1/defaults service. It includes information about default imagery,...
Definition Defaults.h:99
Options to be passed to Connection::tokens.
Definition Connection.h:34
std::optional< std::string > search
One or more keywords separated by whitespace by which to filter the list of tokens....
Definition Connection.h:54
std::optional< int32_t > page
The page number, where the first page of results is page 1 (not 0).
Definition Connection.h:47
std::optional< std::string > sortBy
The property by which to sort results. Valid values are "NAME" and "LAST_USED".
Definition Connection.h:60
std::optional< int32_t > limit
The maximum number of tokens to return in a single page.
Definition Connection.h:42
std::optional< SortOrder > sortOrder
The property by which to sort results. Valid values are "NAME" and "LAST_USED".
Definition Connection.h:66
Contains of a Cesium ion user.
Definition Profile.h:36
A response from Cesium ion.
Definition Response.h:19
A list of Cesium ion access tokens, as returned by the "List Tokens" service.
Definition TokenList.h:11