* Standardized header ordering for C++ repo * Reordered categories to move private headers above public headers; added space between categories to enable future flexibility
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <azure/identity/managed_identity_credential.hpp>
|
|
#include <azure/service/client.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
int main()
|
|
{
|
|
try
|
|
{
|
|
// Step 1: Create a ManagedIdentityCredential instance.
|
|
// Managed Identity Credential would be available in some environments such as on Azure VMs.
|
|
// See documentation for details.
|
|
auto managedIdentityCredential = std::make_shared<Azure::Identity::ManagedIdentityCredential>();
|
|
|
|
// Step 2: Pass the credential to an Azure Service Client.
|
|
Azure::Service::Client azureServiceClient("serviceUrl", managedIdentityCredential);
|
|
|
|
// Step 3: Start using the Azure Service Client.
|
|
azureServiceClient.DoSomething(Azure::Core::Context::ApplicationContext);
|
|
|
|
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;
|
|
}
|