MCPcopy Create free account
hub / github.com/audacity/audacity / Authorize

Method Authorize

libraries/lib-cloud-audiocom/OAuthService.cpp:384–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382}
383
384void OAuthService::Authorize(std::string_view email,
385 std::string_view password,
386 AuthSuccessCallback onSuccess,
387 AuthFailureCallback onFailure,
388 AudiocomTrace trace)
389{
390 using namespace audacity::network_manager;
391 using rapidjson::StringRef;
392
393 rapidjson::Document document;
394 document.SetObject();
395
396 WriteCommonFields(document, "password", "all");
397
398 document.AddMember(
399 "username", StringRef(email.data(), email.size()),
400 document.GetAllocator());
401
402 document.AddMember(
403 "password", StringRef(password.data(), password.size()),
404 document.GetAllocator());
405
406 rapidjson::StringBuffer buffer;
407 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
408 document.Accept(writer);
409
410 Request request(GetServiceConfig().GetAPIUrl("/auth/token"));
411 request.setHeader(common_headers::ContentType, common_content_types::ApplicationJson);
412 request.setHeader(common_headers::Accept, common_content_types::ApplicationJson);
413
414 SetOptionalHeaders(request);
415
416 auto response = NetworkManager::GetInstance().doPost(request, buffer.GetString(), buffer.GetSize());
417 response->setRequestFinishedCallback(
418 [response, this, trace,
419 onSuccess = std::move(onSuccess),
420 onFailure = std::move(onFailure)](auto) mutable
421 {
422 const auto httpCode = response->getHTTPCode();
423 const auto body = response->readAll<std::string>();
424 if(httpCode == 200)
425 ParseTokenResponse(body, std::move(onSuccess), std::move(onFailure), trace, false);
426 else
427 {
428 if(onFailure)
429 onFailure(httpCode, body);
430
431 SafePublish({ {}, body, trace, false, false });
432 }
433 });
434}
435
436void OAuthService::Register(std::string_view email,
437 std::string_view password,

Callers 1

ContinueSignInMethod · 0.80

Calls 12

WriteCommonFieldsFunction · 0.85
SetOptionalHeadersFunction · 0.85
moveFunction · 0.85
GetAPIUrlMethod · 0.80
setHeaderMethod · 0.80
doPostMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
GetStringMethod · 0.45
GetSizeMethod · 0.45
getHTTPCodeMethod · 0.45

Tested by

no test coverage detected