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

Method completeTokenExchange

CesiumClientCommon/src/OAuth2PKCE.cpp:356–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356CesiumAsync::Future<Result<OAuth2TokenResponse>>
357OAuth2PKCE::completeTokenExchange(
358 const CesiumAsync::AsyncSystem& asyncSystem,
359 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
360 const OAuth2ClientOptions& clientOptions,
361 const std::string& tokenEndpointUrl,
362 const std::string& code,
363 const std::string& redirectUrl,
364 const std::string& codeVerifier) {
365 std::string contentType = "application/json";
366 std::span<const std::byte> payload;
367 rapidjson::StringBuffer postBuffer;
368 rapidjson::Writer<rapidjson::StringBuffer> writer(postBuffer);
369 std::string queryStr;
370
371 if (clientOptions.useJsonBody) {
372 writer.StartObject();
373 writer.Key("grant_type");
374 writer.String("authorization_code");
375 writer.Key("client_id");
376 writer.String(clientOptions.clientID.c_str());
377 writer.Key("code");
378 writer.String(code.c_str(), rapidjson::SizeType(code.size()));
379 writer.Key("redirect_uri");
380 writer.String(redirectUrl.c_str(), rapidjson::SizeType(redirectUrl.size()));
381 writer.Key("code_verifier");
382 writer.String(
383 codeVerifier.c_str(),
384 rapidjson::SizeType(codeVerifier.size()));
385 writer.EndObject();
386
387 payload = std::span<const std::byte>(
388 reinterpret_cast<const std::byte*>(postBuffer.GetString()),
389 reinterpret_cast<const std::byte*>(
390 postBuffer.GetString() + postBuffer.GetSize()));
391 } else {
392 CesiumUtility::UriQuery tokenEndpointQuery;
393 tokenEndpointQuery.setValue("grant_type", "authorization_code");
394 tokenEndpointQuery.setValue("client_id", clientOptions.clientID);
395 tokenEndpointQuery.setValue("code", code);
396 tokenEndpointQuery.setValue("redirect_uri", redirectUrl);
397 tokenEndpointQuery.setValue("code_verifier", codeVerifier);
398 queryStr = tokenEndpointQuery.toQueryString();
399 payload = std::span<const std::byte>(
400 reinterpret_cast<const std::byte*>(queryStr.data()),
401 reinterpret_cast<const std::byte*>(queryStr.data() + queryStr.size()));
402
403 contentType = "application/x-www-form-urlencoded";
404 }
405
406 return pAssetAccessor
407 ->request(
408 asyncSystem,
409 "POST",
410 tokenEndpointUrl,
411 {{"Content-Type", contentType}, {"Accept", "application/json"}},
412 payload)
413 .thenInWorkerThread(

Callers

nothing calls this directly

Calls 15

parseErrorResponseFunction · 0.85
formatFunction · 0.85
getStringOrDefaultFunction · 0.85
setValueMethod · 0.80
toQueryStringMethod · 0.80
StartObjectMethod · 0.45
KeyMethod · 0.45
StringMethod · 0.45
sizeMethod · 0.45
EndObjectMethod · 0.45
dataMethod · 0.45
thenInWorkerThreadMethod · 0.45

Tested by

no test coverage detected