1919
2020#include " olp/authentication/AuthenticationClient.h"
2121
22- #include < chrono>
23- #include < sstream>
24-
25- #include < olp/core/client/PendingRequests.h>
2622#include < rapidjson/document.h>
2723#include < rapidjson/istreamwrapper.h>
2824#include < rapidjson/stringbuffer.h>
2925#include < rapidjson/writer.h>
26+
27+ #include < chrono>
28+ #include < sstream>
29+
3030#include < boost/uuid/uuid.hpp>
3131#include < boost/uuid/uuid_generators.hpp>
3232#include < boost/uuid/uuid_io.hpp>
4242#include " olp/core/client/CancellationToken.h"
4343#include " olp/core/client/ErrorCode.h"
4444#include " olp/core/client/OlpClient.h"
45+ #include " olp/core/client/PendingRequests.h"
4546#include " olp/core/http/HttpStatusCode.h"
4647#include " olp/core/http/Network.h"
4748#include " olp/core/http/NetworkConstants.h"
5455#include " olp/core/utils/LruCache.h"
5556#include " olp/core/utils/Url.h"
5657
57- using namespace olp ::thread;
58- using namespace olp ::utils;
59-
6058namespace {
6159using namespace olp ::authentication;
6260
@@ -111,7 +109,7 @@ constexpr auto kVersion = "1.0";
111109constexpr auto kHmac = " HMAC-SHA256" ;
112110
113111void ExecuteOrSchedule (
114- std::shared_ptr<olp::thread::TaskScheduler>& task_scheduler,
112+ const std::shared_ptr<olp::thread::TaskScheduler>& task_scheduler,
115113 olp::thread::TaskScheduler::CallFuncType&& func) {
116114 if (!task_scheduler) {
117115 // User didn't specify a TaskScheduler, execute sync
@@ -137,7 +135,7 @@ void ExecuteOrSchedule(
137135 */
138136template <typename Function, typename Callback, typename ... Args>
139137inline olp::client::CancellationToken AddTask (
140- std::shared_ptr<olp::thread::TaskScheduler>& task_scheduler,
138+ const std::shared_ptr<olp::thread::TaskScheduler>& task_scheduler,
141139 const std::shared_ptr<olp::client::PendingRequests>& pending_requests,
142140 Function task, Callback callback, Args&&... args) {
143141 auto context = olp::client::TaskContext::Create (
@@ -247,11 +245,12 @@ enum class FederatedSignInType { FacebookSignIn, GoogleSignIn, ArcgisSignIn };
247245class AuthenticationClient ::Impl final {
248246 public:
249247 // / The sign in cache alias type
250- using SignInCacheType = Atomic<utils::LruCache<std::string, SignInResult>>;
248+ using SignInCacheType =
249+ thread::Atomic<utils::LruCache<std::string, SignInResult>>;
251250
252251 // / The sign in user cache alias type
253252 using SignInUserCacheType =
254- Atomic<utils::LruCache<std::string, SignInUserResult>>;
253+ thread:: Atomic<utils::LruCache<std::string, SignInUserResult>>;
255254
256255 /* *
257256 * @brief Constructor
@@ -264,7 +263,7 @@ class AuthenticationClient::Impl final {
264263 * @param settings The authentication settings that can be used to configure
265264 * the `Impl` instance.
266265 */
267- Impl (AuthenticationSettings settings);
266+ explicit Impl (AuthenticationSettings settings);
268267
269268 /* *
270269 * @brief Destructor
@@ -318,13 +317,6 @@ class AuthenticationClient::Impl final {
318317 client::CancellationToken IntrospectApp (std::string access_token,
319318 IntrospectAppCallback callback);
320319
321- void SetNetworkProxySettings (
322- const http::NetworkProxySettings& proxy_settings);
323-
324- void SetNetwork (std::shared_ptr<http::Network> network);
325-
326- void SetTaskScheduler (std::shared_ptr<TaskScheduler> task_scheduler);
327-
328320 private:
329321 using TimeResponse = client::ApiResponse<time_t , client::ApiError>;
330322 using TimeCallback = std::function<void (TimeResponse)>;
@@ -369,25 +361,6 @@ class AuthenticationClient::Impl final {
369361 mutable std::mutex token_mutex_;
370362};
371363
372- void AuthenticationClient::Impl::SetNetworkProxySettings (
373- const http::NetworkProxySettings& proxy_settings) {
374- settings_.network_proxy_settings = proxy_settings;
375- }
376-
377- void AuthenticationClient::Impl::SetNetwork (
378- std::shared_ptr<http::Network> network) {
379- if (settings_.network_request_handler != network) {
380- settings_.network_request_handler = std::move (network);
381- }
382- }
383-
384- void AuthenticationClient::Impl::SetTaskScheduler (
385- std::shared_ptr<TaskScheduler> task_scheduler) {
386- if (settings_.task_scheduler != task_scheduler) {
387- settings_.task_scheduler = std::move (task_scheduler);
388- }
389- }
390-
391364AuthenticationClient::Impl::Impl (const std::string& authentication_server_url,
392365 size_t token_cache_limit)
393366 : client_token_cache_(std::make_shared<SignInCacheType>(token_cache_limit)),
@@ -557,7 +530,8 @@ AuthenticationClient::Impl::ParseTimeResponse(std::stringstream& payload) {
557530 return timestamp_it->value .GetUint ();
558531}
559532
560- client::CancellationToken AuthenticationClient::Impl::GetTime (TimeCallback callback) {
533+ client::CancellationToken AuthenticationClient::Impl::GetTime (
534+ TimeCallback callback) {
561535 if (settings_.use_system_time ) {
562536 callback (
563537 std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ()));
@@ -985,8 +959,8 @@ std::string AuthenticationClient::Impl::generateHeader(
985959 const time_t & timestamp) {
986960 std::string uid = generateUid ();
987961 const std::string currentTime = std::to_string (timestamp);
988- const std::string encodedUri = Url::Encode (url);
989- const std::string encodedQuery = Url::Encode (
962+ const std::string encodedUri = utils:: Url::Encode (url);
963+ const std::string encodedQuery = utils:: Url::Encode (
990964 kOauthConsumerKey + kParamEquals + credentials.GetKey () + kParamAdd +
991965 kOauthNonce + kParamEquals + uid + kParamAdd + kOauthSignatureMethod +
992966 kParamEquals + kHmac + kParamAdd + kOauthTimestamp + kParamEquals +
@@ -998,14 +972,14 @@ std::string AuthenticationClient::Impl::generateHeader(
998972 auto signature = base64Encode (hmacResult);
999973 std::string authorization =
1000974 " OAuth " + kOauthConsumerKey + kParamEquals + kParamQuote +
1001- Url::Encode (credentials.GetKey ()) + kParamQuote + kParamComma +
1002- kOauthNonce + kParamEquals + kParamQuote + Url::Encode (uid) +
975+ utils:: Url::Encode (credentials.GetKey ()) + kParamQuote + kParamComma +
976+ kOauthNonce + kParamEquals + kParamQuote + utils:: Url::Encode (uid) +
1003977 kParamQuote + kParamComma + kOauthSignatureMethod + kParamEquals +
1004978 kParamQuote + kHmac + kParamQuote + kParamComma + kOauthTimestamp +
1005- kParamEquals + kParamQuote + Url::Encode (currentTime) + kParamQuote +
1006- kParamComma + kOauthVersion + kParamEquals + kParamQuote + kVersion +
1007- kParamQuote + kParamComma + kOauthSignature + kParamEquals + kParamQuote +
1008- Url::Encode (signature) + kParamQuote ;
979+ kParamEquals + kParamQuote + utils:: Url::Encode (currentTime) +
980+ kParamQuote + kParamComma + kOauthVersion + kParamEquals + kParamQuote +
981+ kVersion + kParamQuote + kParamComma + kOauthSignature + kParamEquals +
982+ kParamQuote + utils:: Url::Encode (signature) + kParamQuote ;
1009983
1010984 return authorization;
1011985}
@@ -1230,10 +1204,6 @@ std::string AuthenticationClient::Impl::generateUid() {
12301204 }
12311205}
12321206
1233- AuthenticationClient::AuthenticationClient (
1234- const std::string& authenticationServerUrl, size_t tokenCacheLimit)
1235- : impl_(std::make_unique<Impl>(authenticationServerUrl, tokenCacheLimit)) {}
1236-
12371207AuthenticationClient::AuthenticationClient (AuthenticationSettings settings)
12381208 : impl_(std::make_unique<Impl>(std::move(settings))) {}
12391209
@@ -1309,19 +1279,5 @@ client::CancellationToken AuthenticationClient::IntrospectApp(
13091279 return impl_->IntrospectApp (std::move (access_token), std::move (callback));
13101280}
13111281
1312- void AuthenticationClient::SetNetworkProxySettings (
1313- const http::NetworkProxySettings& proxy_settings) {
1314- impl_->SetNetworkProxySettings (proxy_settings);
1315- }
1316-
1317- void AuthenticationClient::SetNetwork (std::shared_ptr<http::Network> network) {
1318- impl_->SetNetwork (network);
1319- }
1320-
1321- void AuthenticationClient::SetTaskScheduler (
1322- std::shared_ptr<TaskScheduler> task_scheduler) {
1323- impl_->SetTaskScheduler (task_scheduler);
1324- }
1325-
13261282} // namespace authentication
13271283} // namespace olp
0 commit comments