azure-identity
client_certificate_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 
11 #include "azure/identity/detail/client_credential_core.hpp"
13 
14 #include <azure/core/credentials/credentials.hpp>
15 #include <azure/core/credentials/token_credential_options.hpp>
16 #include <azure/core/internal/unique_handle.hpp>
17 #include <azure/core/url.hpp>
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 namespace Azure { namespace Identity {
24  namespace _detail {
25  class TokenCredentialImpl;
26 
27  void FreePkeyImpl(void* pkey);
28 
29  template <typename> struct UniquePkeyHelper;
30  template <> struct UniquePkeyHelper<void*>
31  {
32  static void FreePkey(void* pkey) { FreePkeyImpl(pkey); }
33  using type = Azure::Core::_internal::BasicUniqueHandle<void, FreePkey>;
34  };
35 
36  using UniquePkeyHandle = Azure::Core::_internal::UniqueHandle<void*, UniquePkeyHelper>;
37  } // namespace _detail
38 
43  struct ClientCertificateCredentialOptions final : public Core::Credentials::TokenCredentialOptions
44  {
53  std::string AuthorityHost = _detail::ClientCredentialCore::AadGlobalAuthority;
54 
60  std::vector<std::string> AdditionallyAllowedTenants;
61  };
62 
68  class ClientCertificateCredential final : public Core::Credentials::TokenCredential {
69  private:
70  _detail::TokenCache m_tokenCache;
71  _detail::ClientCredentialCore m_clientCredentialCore;
72  std::unique_ptr<_detail::TokenCredentialImpl> m_tokenCredentialImpl;
73  std::string m_requestBody;
74  std::string m_tokenPayloadStaticPart;
75  std::string m_tokenHeaderEncoded;
76  _detail::UniquePkeyHandle m_pkey;
77 
79  std::string tenantId,
80  std::string const& clientId,
81  std::string const& clientCertificatePath,
82  std::string const& authorityHost,
83  std::vector<std::string> additionallyAllowedTenants,
84  Core::Credentials::TokenCredentialOptions const& options);
85 
86  public:
96  std::string tenantId,
97  std::string const& clientId,
98  std::string const& clientCertificatePath,
99  Core::Credentials::TokenCredentialOptions const& options
100  = Core::Credentials::TokenCredentialOptions());
101 
111  std::string tenantId,
112  std::string const& clientId,
113  std::string const& clientCertificatePath,
114  ClientCertificateCredentialOptions const& options);
115 
121 
130  Core::Credentials::AccessToken GetToken(
131  Core::Credentials::TokenRequestContext const& tokenRequestContext,
132  Core::Context const& context) const override;
133  };
134 
135 }} // namespace Azure::Identity
Client Certificate Credential authenticates with the Azure services using a Tenant ID,...
Definition: client_certificate_credential.hpp:68
Core::Credentials::AccessToken GetToken(Core::Credentials::TokenRequestContext const &tokenRequestContext, Core::Context const &context) const override
Gets an authentication token.
Definition: client_certificate_credential.cpp:206
ClientCertificateCredential(std::string tenantId, std::string const &clientId, std::string const &clientCertificatePath, Core::Credentials::TokenCredentialOptions const &options=Core::Credentials::TokenCredentialOptions())
Constructs a Client Secret Credential.
~ClientCertificateCredential() override
Destructs ClientCertificateCredential.
Azure SDK abstractions.
Definition: azure_cli_credential.hpp:22
Options for client certificate authentication.
Definition: client_certificate_credential.hpp:44
std::vector< std::string > AdditionallyAllowedTenants
For multi-tenant applications, specifies additional tenants for which the credential may acquire toke...
Definition: client_certificate_credential.hpp:60
std::string AuthorityHost
Authentication authority URL.
Definition: client_certificate_credential.hpp:53
Token cache.