* Deprecated Azure::Core::ApplicationContext because its use is confusing and inconsistent with the original design. --------- Co-authored-by: Rick Winter <rick.winter@microsoft.com> Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Co-authored-by: Ahson Khan <ahkha@microsoft.com>
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
#include <azure/identity/environment_credential.hpp>
|
|
#include <azure/service/client.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
int main()
|
|
{
|
|
try
|
|
{
|
|
// Step 1: Create an EnvironmentCredential instance.
|
|
// Environment Credential would read its parameters from the environment variables, such as
|
|
// AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET. See documentation for details.
|
|
auto environmentCredential = std::make_shared<Azure::Identity::EnvironmentCredential>();
|
|
|
|
// Step 2: Pass the credential to an Azure Service Client.
|
|
Azure::Service::Client azureServiceClient("serviceUrl", environmentCredential);
|
|
|
|
// Step 3: Start using the Azure Service Client.
|
|
azureServiceClient.DoSomething();
|
|
|
|
std::cout << "Success!" << std::endl;
|
|
}
|
|
catch (const Azure::Core::Credentials::AuthenticationException& exception)
|
|
{
|
|
// Step 4: Handle authentication errors, if needed
|
|
// (invalid credential parameters, insufficient permissions).
|
|
std::cout << "Authentication error: " << exception.what() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|