6#include <azure/core/http/policies/policy.hpp>
11namespace Azure {
namespace Data {
namespace Tables {
namespace _detail {
namespace Policies {
13 class TenantBearerTokenAuthenticationPolicy final
14 :
public Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy {
23 explicit TenantBearerTokenAuthenticationPolicy(
24 std::shared_ptr<const Azure::Core::Credentials::TokenCredential> credential,
25 Azure::Core::Credentials::TokenRequestContext tokenRequestContext,
26 bool enableTenantDiscovery)
27 : BearerTokenAuthenticationPolicy(std::move(credential), tokenRequestContext),
28 m_scopes{tokenRequestContext.Scopes}, m_safeTenantId{tokenRequestContext.TenantId},
29 m_enableTenantDiscovery{enableTenantDiscovery}
33 ~TenantBearerTokenAuthenticationPolicy()
override {}
35 std::unique_ptr<HttpPolicy> Clone()
const override
37 return std::unique_ptr<HttpPolicy>(
new TenantBearerTokenAuthenticationPolicy(*
this));
44 explicit SafeTenantId(std::string tenantId) : m_tenantId{std::move(tenantId)} {}
46 SafeTenantId(
const SafeTenantId& other) : m_tenantId{other.Get()} {}
48 std::string Get()
const
50 std::shared_lock<std::shared_timed_mutex> lock(m_tenantIdMutex);
54 void Set(
const std::string& tenantId)
56 std::unique_lock<std::shared_timed_mutex> lock(m_tenantIdMutex);
57 m_tenantId = tenantId;
61 std::string m_tenantId;
62 mutable std::shared_timed_mutex m_tenantIdMutex;
65 std::vector<std::string> m_scopes;
66 mutable SafeTenantId m_safeTenantId;
67 bool m_enableTenantDiscovery;
69 std::unique_ptr<Azure::Core::Http::RawResponse> AuthorizeAndSendRequest(
70 Azure::Core::Http::Request& request,
71 Azure::Core::Http::Policies::NextHttpPolicy& nextPolicy,
72 Azure::Core::Context
const& context)
const override;
74 bool AuthorizeRequestOnChallenge(
75 std::string
const& challenge,
76 Azure::Core::Http ::Request& request,
77 Azure::Core::Context
const& context)
const override;