azure-identity
client_secret_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/url.hpp>
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 namespace Azure { namespace Identity {
23  namespace _detail {
24  class TokenCredentialImpl;
25  } // namespace _detail
26 
31  struct ClientSecretCredentialOptions final : public Core::Credentials::TokenCredentialOptions
32  {
41  std::string AuthorityHost = _detail::ClientCredentialCore::AadGlobalAuthority;
42 
48  std::vector<std::string> AdditionallyAllowedTenants;
49  };
50 
56  class ClientSecretCredential final : public Core::Credentials::TokenCredential {
57  private:
58  _detail::TokenCache m_tokenCache;
59  _detail::ClientCredentialCore m_clientCredentialCore;
60  std::unique_ptr<_detail::TokenCredentialImpl> m_tokenCredentialImpl;
61  std::string m_requestBody;
62 
64  std::string tenantId,
65  std::string const& clientId,
66  std::string const& clientSecret,
67  std::string const& authorityHost,
68  std::vector<std::string> additionallyAllowedTenants,
69  Core::Credentials::TokenCredentialOptions const& options);
70 
71  public:
80  explicit ClientSecretCredential(
81  std::string tenantId,
82  std::string const& clientId,
83  std::string const& clientSecret,
84  ClientSecretCredentialOptions const& options);
85 
94  explicit ClientSecretCredential(
95  std::string tenantId,
96  std::string const& clientId,
97  std::string const& clientSecret,
98  Core::Credentials::TokenCredentialOptions const& options
99  = Core::Credentials::TokenCredentialOptions());
100 
106 
117  Core::Credentials::AccessToken GetToken(
118  Core::Credentials::TokenRequestContext const& tokenRequestContext,
119  Core::Context const& context) const override;
120  };
121 
122 }} // namespace Azure::Identity
Client Secret Credential authenticates with the Azure services using a Tenant ID, Client ID and a cli...
Definition: client_secret_credential.hpp:56
~ClientSecretCredential() override
Destructs ClientSecretCredential.
Core::Credentials::AccessToken GetToken(Core::Credentials::TokenRequestContext const &tokenRequestContext, Core::Context const &context) const override
Gets an authentication token.
Definition: client_secret_credential.cpp:68
Azure SDK abstractions.
Definition: azure_cli_credential.hpp:22
Options for token authentication.
Definition: client_secret_credential.hpp:32
std::vector< std::string > AdditionallyAllowedTenants
For multi-tenant applications, specifies additional tenants for which the credential may acquire toke...
Definition: client_secret_credential.hpp:48
std::string AuthorityHost
Authentication authority URL.
Definition: client_secret_credential.hpp:41
Token cache.