|
15 | 15 | #include <rapidjson/error/en.h>
|
16 | 16 | #include <rapidjson/stringbuffer.h>
|
17 | 17 | #include <rapidjson/writer.h>
|
| 18 | +#include <uriparser/Uri.h> |
18 | 19 |
|
19 | 20 | #include <thread>
|
20 | 21 |
|
@@ -134,7 +135,7 @@ std::string createAuthorizationErrorHtml(
|
134 | 135 | authorizeUrl =
|
135 | 136 | Uri::addQuery(authorizeUrl, "client_id", std::to_string(clientID));
|
136 | 137 | authorizeUrl =
|
137 |
| - Uri::addQuery(authorizeUrl, "scope", joinToString(scopes, " ")); |
| 138 | + Uri::addQuery(authorizeUrl, "scope", joinToString(scopes, "%20")); |
138 | 139 | authorizeUrl = Uri::addQuery(authorizeUrl, "redirect_uri", redirectUrl);
|
139 | 140 | authorizeUrl = Uri::addQuery(authorizeUrl, "state", state);
|
140 | 141 | authorizeUrl = Uri::addQuery(authorizeUrl, "code_challenge_method", "S256");
|
@@ -373,6 +374,51 @@ Asset jsonToAsset(const rapidjson::Value& item) {
|
373 | 374 |
|
374 | 375 | } // namespace
|
375 | 376 |
|
| 377 | +CesiumAsync::Future<std::optional<std::string>> |
| 378 | +CesiumIonClient::Connection::getApiUrl( |
| 379 | + const CesiumAsync::AsyncSystem& asyncSystem, |
| 380 | + const std::shared_ptr<IAssetAccessor>& pAssetAccessor, |
| 381 | + const std::string& ionUrl) { |
| 382 | + std::string configUrl = Uri::resolve(ionUrl, "config.json"); |
| 383 | + if (configUrl == "config.json") { |
| 384 | + return asyncSystem.createResolvedFuture<std::optional<std::string>>( |
| 385 | + std::nullopt); |
| 386 | + } |
| 387 | + return pAssetAccessor->get(asyncSystem, configUrl) |
| 388 | + .thenImmediately([ionUrl](std::shared_ptr<IAssetRequest>&& pRequest) { |
| 389 | + const IAssetResponse* pResponse = pRequest->response(); |
| 390 | + if (pResponse && pResponse->statusCode() >= 200 && |
| 391 | + pResponse->statusCode() < 300) { |
| 392 | + rapidjson::Document d; |
| 393 | + if (parseJsonObject(pResponse, d) && d.IsObject()) { |
| 394 | + const auto itr = d.FindMember("apiHostname"); |
| 395 | + if (itr != d.MemberEnd() && itr->value.IsString()) { |
| 396 | + return std::make_optional<std::string>(itr->value.GetString()); |
| 397 | + } |
| 398 | + } |
| 399 | + } |
| 400 | + |
| 401 | + UriUriA newUri; |
| 402 | + if (uriParseSingleUriA(&newUri, ionUrl.c_str(), nullptr) != |
| 403 | + URI_SUCCESS) { |
| 404 | + return std::optional<std::string>(); |
| 405 | + } |
| 406 | + |
| 407 | + std::string hostName = |
| 408 | + std::string(newUri.hostText.first, newUri.hostText.afterLast); |
| 409 | + std::string scheme = |
| 410 | + std::string(newUri.scheme.first, newUri.scheme.afterLast); |
| 411 | + |
| 412 | + uriFreeUriMembersA(&newUri); |
| 413 | + |
| 414 | + return std::make_optional<std::string>( |
| 415 | + scheme + "://api." + hostName + '/'); |
| 416 | + }) |
| 417 | + .catchImmediately([](std::exception&&) { |
| 418 | + return std::optional<std::string>(std::nullopt); |
| 419 | + }); |
| 420 | +} |
| 421 | + |
376 | 422 | CesiumAsync::Future<Response<Assets>> Connection::assets() const {
|
377 | 423 | return this->_pAssetAccessor
|
378 | 424 | ->get(
|
|
0 commit comments