| 469 | } |
| 470 | |
| 471 | CesiumAsync::Future<CesiumUtility::Result<OAuth2TokenResponse>> |
| 472 | OAuth2PKCE::refresh( |
| 473 | const CesiumAsync::AsyncSystem& asyncSystem, |
| 474 | const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor, |
| 475 | const OAuth2ClientOptions& clientOptions, |
| 476 | const std::string& refreshBaseUrl, |
| 477 | const std::string& refreshToken) { |
| 478 | const std::string redirectUrl = |
| 479 | clientOptions.redirectPort |
| 480 | ? Uri::resolve( |
| 481 | "http://127.0.0.1:" + |
| 482 | std::to_string(*clientOptions.redirectPort), |
| 483 | clientOptions.redirectPath) |
| 484 | : Uri::resolve("http://127.0.0.1", clientOptions.redirectPath); |
| 485 | |
| 486 | std::string contentType = "application/json"; |
| 487 | std::span<const std::byte> payload; |
| 488 | rapidjson::StringBuffer postBuffer; |
| 489 | rapidjson::Writer<rapidjson::StringBuffer> writer(postBuffer); |
| 490 | std::string postBody; |
| 491 | |
| 492 | if (clientOptions.useJsonBody) { |
| 493 | writer.StartObject(); |
| 494 | writer.Key("grant_type"); |
| 495 | writer.String("refresh_token"); |
| 496 | writer.Key("client_id"); |
| 497 | writer.String(clientOptions.clientID.c_str()); |
| 498 | writer.Key("redirect_uri"); |
| 499 | writer.String(redirectUrl.c_str(), rapidjson::SizeType(redirectUrl.size())); |
| 500 | writer.Key("refresh_token"); |
| 501 | writer.String( |
| 502 | refreshToken.c_str(), |
| 503 | rapidjson::SizeType(refreshToken.size())); |
| 504 | writer.EndObject(); |
| 505 | |
| 506 | payload = std::span<const std::byte>( |
| 507 | reinterpret_cast<const std::byte*>(postBuffer.GetString()), |
| 508 | postBuffer.GetSize()); |
| 509 | } else { |
| 510 | CesiumUtility::UriQuery refreshEndpointQuery; |
| 511 | refreshEndpointQuery.setValue("grant_type", "refresh_token"); |
| 512 | refreshEndpointQuery.setValue("client_id", clientOptions.clientID); |
| 513 | refreshEndpointQuery.setValue("redirect_uri", redirectUrl); |
| 514 | refreshEndpointQuery.setValue("refresh_token", refreshToken); |
| 515 | postBody = refreshEndpointQuery.toQueryString(); |
| 516 | payload = std::span<const std::byte>( |
| 517 | reinterpret_cast<const std::byte*>(postBody.data()), |
| 518 | postBody.size()); |
| 519 | contentType = "application/x-www-form-urlencoded"; |
| 520 | } |
| 521 | |
| 522 | return pAssetAccessor |
| 523 | ->request( |
| 524 | asyncSystem, |
| 525 | "POST", |
| 526 | refreshBaseUrl, |
| 527 | {{"Content-Type", contentType}, {"Accept", "application/json"}}, |
| 528 | payload) |
nothing calls this directly
no test coverage detected