azure-identity
Loading...
Searching...
No Matches
client_certificate_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
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
23namespace Azure { namespace Identity {
24 namespace _detail {
25 class TokenCredentialImpl;
26
27 void FreePrivateKeyImpl(void* pkey);
28
29 template <typename> struct UniquePrivateKeyHelper;
30 template <> struct UniquePrivateKeyHelper<void*>
31 {
32 static void FreePrivateKey(void* pkey) { FreePrivateKeyImpl(pkey); }
33 using type = Azure::Core::_internal::BasicUniqueHandle<void, FreePrivateKey>;
34 };
35
36 using UniquePrivateKey = Azure::Core::_internal::UniqueHandle<void*, UniquePrivateKeyHelper>;
37 } // namespace _detail
38
43 struct ClientCertificateCredentialOptions final : public Core::Credentials::TokenCredentialOptions
44 {
55 std::string AuthorityHost = _detail::DefaultOptionValues::GetAuthorityHost();
56
62 std::vector<std::string> AdditionallyAllowedTenants;
63
73 };
74
80 class ClientCertificateCredential final : public Core::Credentials::TokenCredential {
81 private:
82 _detail::TokenCache m_tokenCache;
83 _detail::ClientCredentialCore m_clientCredentialCore;
84 std::unique_ptr<_detail::TokenCredentialImpl> m_tokenCredentialImpl;
85 std::string m_requestBody;
86 std::string m_tokenPayloadStaticPart;
87 std::string m_tokenHeaderEncoded;
88 _detail::UniquePrivateKey m_pkey;
89
91 std::string tenantId,
92 std::string const& clientId,
93 std::string const& clientCertificatePath,
94 std::string const& authorityHost,
95 std::vector<std::string> additionallyAllowedTenants,
96 bool sendCertificateChain,
97 Core::Credentials::TokenCredentialOptions const& options);
98
100 std::string tenantId,
101 std::string const& clientId,
102 std::string const& clientCertificate,
103 std::string const& privateKey,
104 std::string const& authorityHost,
105 std::vector<std::string> additionallyAllowedTenants,
106 bool sendCertificateChain,
107 Core::Credentials::TokenCredentialOptions const& options);
108
109 public:
120 std::string tenantId,
121 std::string const& clientId,
122 std::string const& clientCertificatePath,
123 Core::Credentials::TokenCredentialOptions const& options
124 = Core::Credentials::TokenCredentialOptions());
125
138 std::string tenantId,
139 std::string const& clientId,
140 std::string const& clientCertificate,
141 std::string const& privateKey,
142 ClientCertificateCredentialOptions const& options = {});
143
154 std::string tenantId,
155 std::string const& clientId,
156 std::string const& clientCertificatePath,
158
164
173 Core::Credentials::AccessToken GetToken(
174 Core::Credentials::TokenRequestContext const& tokenRequestContext,
175 Core::Context const& context) const override;
176 };
177
178}} // namespace Azure::Identity
Client Certificate Credential authenticates with the Azure services using a Tenant ID,...
Definition client_certificate_credential.hpp:80
Core::Credentials::AccessToken GetToken(Core::Credentials::TokenRequestContext const &tokenRequestContext, Core::Context const &context) const override
Gets an authentication token.
Definition client_certificate_credential.cpp:678
~ClientCertificateCredential() override
Destructs ClientCertificateCredential.
Options for client certificate authentication.
Definition client_certificate_credential.hpp:44
bool SendCertificateChain
SendCertificateChain controls whether the credential sends the public certificate chain in the x5c he...
Definition client_certificate_credential.hpp:72
std::vector< std::string > AdditionallyAllowedTenants
For multi-tenant applications, specifies additional tenants for which the credential may acquire toke...
Definition client_certificate_credential.hpp:62
std::string AuthorityHost
Authentication authority URL.
Definition client_certificate_credential.hpp:55
Token cache.