azure-identity
Loading...
Searching...
No Matches
azure_cli_credential.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
9#pragma once
10
12
13#include <azure/core/credentials/credentials.hpp>
14#include <azure/core/credentials/token_credential_options.hpp>
15#include <azure/core/datetime.hpp>
16
17#include <chrono>
18#include <string>
19#include <vector>
20
21namespace Azure { namespace Identity {
25 struct AzureCliCredentialOptions final : public Core::Credentials::TokenCredentialOptions
26 {
32 std::string TenantId;
33
37 DateTime::duration CliProcessTimeout
38 = std::chrono::seconds(13); // Value was taken from .NET SDK.
39
45 std::vector<std::string> AdditionallyAllowedTenants;
46 };
47
53#if !defined(_azure_TESTING_BUILD)
54 final
55#endif
56 : public Core::Credentials::TokenCredential {
57 protected:
59 _detail::TokenCache m_tokenCache;
60
62 std::vector<std::string> m_additionallyAllowedTenants;
63
65 std::string m_tenantId;
66
68 DateTime::duration m_cliProcessTimeout;
69
70 private:
71 explicit AzureCliCredential(
72 Core::Credentials::TokenCredentialOptions const& options,
73 std::string tenantId,
74 DateTime::duration cliProcessTimeout,
75 std::vector<std::string> additionallyAllowedTenants);
76
77 void ThrowIfNotSafeCmdLineInput(
78 std::string const& input,
79 std::string const& allowedChars,
80 std::string const& description) const;
81
82 public:
88 explicit AzureCliCredential(AzureCliCredentialOptions const& options = {});
89
95 explicit AzureCliCredential(Core::Credentials::TokenCredentialOptions const& options);
96
105 Core::Credentials::AccessToken GetToken(
106 Core::Credentials::TokenRequestContext const& tokenRequestContext,
107 Core::Context const& context) const override;
108
109#if !defined(_azure_TESTING_BUILD)
110 private:
111#else
112 protected:
113#endif
114 virtual std::string GetAzCommand(std::string const& scopes, std::string const& tenantId) const;
115 virtual int GetLocalTimeToUtcDiffSeconds() const;
116 };
117
118}} // namespace Azure::Identity
Enables authentication to Microsoft Entra ID using Azure CLI to obtain an access token.
Definition azure_cli_credential.hpp:56
Core::Credentials::AccessToken GetToken(Core::Credentials::TokenRequestContext const &tokenRequestContext, Core::Context const &context) const override
Gets an authentication token.
Definition azure_cli_credential.cpp:160
std::vector< std::string > m_additionallyAllowedTenants
Additional tenants which will be allowed for this credential.
Definition azure_cli_credential.hpp:62
_detail::TokenCache m_tokenCache
The cache for the access token.
Definition azure_cli_credential.hpp:59
std::string m_tenantId
The ID of the tenant to which the credential will authenticate by default.
Definition azure_cli_credential.hpp:65
DateTime::duration m_cliProcessTimeout
The CLI process timeout.
Definition azure_cli_credential.hpp:68
Options for configuring the Azure::Identity::AzureCliCredential.
Definition azure_cli_credential.hpp:26
std::string TenantId
The ID of the tenant to which the credential will authenticate by default. If not specified,...
Definition azure_cli_credential.hpp:32
std::vector< std::string > AdditionallyAllowedTenants
For multi-tenant applications, specifies additional tenants for which the credential may acquire toke...
Definition azure_cli_credential.hpp:45
DateTime::duration CliProcessTimeout
The CLI process timeout.
Definition azure_cli_credential.hpp:38
Token cache.