azure-identity
azure_cli_credential.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
9 #pragma once
10 
12 
13 #include <azure/core/credentials/credentials.hpp>
14 #include <azure/core/credentials/token_credential_options.hpp>
15 
16 #include <azure/core/datetime.hpp>
17 
18 #include <chrono>
19 #include <string>
20 #include <vector>
21 
22 namespace Azure { namespace Identity {
26  struct AzureCliCredentialOptions final : public Core::Credentials::TokenCredentialOptions
27  {
33  std::string TenantId;
34 
38  DateTime::duration CliProcessTimeout
39  = std::chrono::seconds(13); // Value was taken from .NET SDK.
40 
46  std::vector<std::string> AdditionallyAllowedTenants;
47  };
48 
54 #if !defined(TESTING_BUILD)
55  final
56 #endif
57  : public Core::Credentials::TokenCredential {
58  protected:
59  _detail::TokenCache m_tokenCache;
60  std::vector<std::string> m_additionallyAllowedTenants;
61  std::string m_tenantId;
62  DateTime::duration m_cliProcessTimeout;
63 
64  private:
65  explicit AzureCliCredential(
66  Core::Credentials::TokenCredentialOptions const& options,
67  std::string tenantId,
68  DateTime::duration cliProcessTimeout,
69  std::vector<std::string> additionallyAllowedTenants);
70 
71  void ThrowIfNotSafeCmdLineInput(std::string const& input, std::string const& description) const;
72 
73  public:
79  explicit AzureCliCredential(AzureCliCredentialOptions const& options = {});
80 
86  explicit AzureCliCredential(Core::Credentials::TokenCredentialOptions const& options);
87 
96  Core::Credentials::AccessToken GetToken(
97  Core::Credentials::TokenRequestContext const& tokenRequestContext,
98  Core::Context const& context) const override;
99 
100 #if !defined(TESTING_BUILD)
101  private:
102 #else
103  protected:
104 #endif
105  virtual std::string GetAzCommand(std::string const& scopes, std::string const& tenantId) const;
106  };
107 
108 }} // namespace Azure::Identity
Enables authentication to Azure Active Directory using Azure CLI to obtain an access token.
Definition: azure_cli_credential.hpp:57
Core::Credentials::AccessToken GetToken(Core::Credentials::TokenRequestContext const &tokenRequestContext, Core::Context const &context) const override
Gets an authentication token.
Definition: azure_cli_credential.cpp:140
AzureCliCredential(Core::Credentials::TokenCredentialOptions const &options)
Constructs an Azure CLI Credential.
Azure SDK abstractions.
Definition: azure_cli_credential.hpp:22
Options for configuring the Azure::Identity::AzureCliCredential.
Definition: azure_cli_credential.hpp:27
std::string TenantId
The ID of the tenant to which the credential will authenticate by default. If not specified,...
Definition: azure_cli_credential.hpp:33
std::vector< std::string > AdditionallyAllowedTenants
For multi-tenant applications, specifies additional tenants for which the credential may acquire toke...
Definition: azure_cli_credential.hpp:46
DateTime::duration CliProcessTimeout
The CLI process timeout.
Definition: azure_cli_credential.hpp:39
Token cache.