diff --git a/samples/helpers/service/CMakeLists.txt b/samples/helpers/service/CMakeLists.txt index 8f25a20ca..af8944052 100644 --- a/samples/helpers/service/CMakeLists.txt +++ b/samples/helpers/service/CMakeLists.txt @@ -10,8 +10,11 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) add_library( service - INTERFACE + OBJECT inc/azure/service/client.hpp -) + src/client.cpp + ) -target_include_directories(service INTERFACE inc) + target_link_libraries(service PUBLIC azure-core) + +target_include_directories(service PUBLIC inc) diff --git a/samples/helpers/service/inc/azure/service/client.hpp b/samples/helpers/service/inc/azure/service/client.hpp index b489445ce..e28b0f687 100644 --- a/samples/helpers/service/inc/azure/service/client.hpp +++ b/samples/helpers/service/inc/azure/service/client.hpp @@ -3,9 +3,11 @@ #pragma once +#include #include #include +#include #include namespace Azure { namespace Service { @@ -26,32 +28,13 @@ namespace Azure { namespace Service { static_cast(serviceUrl); // to suppress the "unused variable" warning. } - void DoSomething(const Core::Context& context) const - { - static_cast(context); // to suppress the "unused variable" warning. - - // This method does nothing, because the purpose of this class is to demonstrate - // how Azure::Identity classes can be used with a generic Azure SDK service client. - // If we have code here that gets the token, it would be up to the user to set it up to be - // valid enough to get a token, which is not critical for the intended demonstration purposes. - // And if user runs this, and authentication is unsuccessful, it may draw an unnecessary - // attention to an irrelevant (to the demo) point. - - // But an oversimplified logic of what a typical Azure SDK client does is below: -#if (0) - // Every client has its own scope. We use management.azure.com here as an example. - Core::Credentials::TokenRequestContext azureServiceClientContext; - azureServiceClientContext.Scopes = {"https://management.azure.com/"}; - - auto authenticationToken = m_credential->GetToken(azureServiceClientContext, context); - - // Now that it has a token, Client can authorize and DoSomething(). - // ... - // ... - - static_cast(authenticationToken); // to suppress the "unused variable" warning. -#endif - } + // This method does nothing, because the purpose of this class is to demonstrate how + // Azure::Identity classes can be used with a generic Azure SDK service client. If we have code + // here that gets the token, it would be up to the user to set it up to be valid enough to get a + // token, which is not critical for the intended demonstration purposes. And if user runs this, + // and authentication is unsuccessful, it may draw an unnecessary attention to an irrelevant (to + // the demo) point. + void DoSomething(const Core::Context& context) const; }; }} // namespace Azure::Service diff --git a/samples/helpers/service/src/client.cpp b/samples/helpers/service/src/client.cpp new file mode 100644 index 000000000..6d8697521 --- /dev/null +++ b/samples/helpers/service/src/client.cpp @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include "azure/service/client.hpp" + +void Azure::Service::Client::DoSomething(const Azure::Core::Context& context) const +{ + static_cast(context); // to suppress the "unused variable" warning. + + // An oversimplified logic of what a typical Azure SDK client does is below: +#if (0) + // Every client has its own scope. We use management.azure.com here as an example. + Core::Credentials::TokenRequestContext azureServiceClientContext; + azureServiceClientContext.Scopes = {"https://management.azure.com/"}; + + auto authenticationToken = m_credential->GetToken(azureServiceClientContext, context); + + // Now that it has a token, Client can authorize and DoSomething(). + // ... + // ... + + static_cast(authenticationToken); // to suppress the "unused variable" warning. +#endif +}