Shorten the names of some long name headers (#4987)
* Shorten the names of some long name headers --------- Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Родитель
4b155b5a72
Коммит
ebf958df23
|
@ -11,7 +11,7 @@
|
|||
#include <azure/core/internal/json/json_optional.hpp>
|
||||
#include <azure/core/internal/json/json_serializable.hpp>
|
||||
#include <azure/keyvault/administration/settings_client.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_authentication_policy.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_auth.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_shared.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "azure/keyvault/certificates/certificate_client.hpp"
|
||||
|
||||
#include "azure/keyvault/shared/keyvault_challenge_based_authentication_policy.hpp"
|
||||
#include "azure/keyvault/shared/keyvault_challenge_based_auth.hpp"
|
||||
#include "azure/keyvault/shared/keyvault_shared.hpp"
|
||||
#include "private/certificate_constants.hpp"
|
||||
#include "private/certificate_serializers.hpp"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <azure/core/exception.hpp>
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_authentication_policy.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_auth.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_shared.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/core/internal/http/pipeline.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_authentication_policy.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_auth.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_shared.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <azure/core/credentials/credentials.hpp>
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_authentication_policy.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_auth.hpp>
|
||||
#include <azure/keyvault/shared/keyvault_shared.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "azure/keyvault/shared/keyvault_challenge_based_authentication_policy.hpp"
|
||||
#include "azure/keyvault/shared/keyvault_challenge_based_auth.hpp"
|
||||
#include "azure/keyvault/shared/keyvault_shared.hpp"
|
||||
|
||||
#include <azure/core/internal/http/pipeline.hpp>
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Key Vault Challenge-Based Authentication Policy.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/core/internal/credentials/authorization_challenge_parser.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace _internal {
|
||||
/**
|
||||
* @brief Challenge-Based Authentication Policy for Key Vault.
|
||||
*
|
||||
*/
|
||||
class KeyVaultChallengeBasedAuthenticationPolicy final
|
||||
: public Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy {
|
||||
private:
|
||||
mutable Core::Credentials::TokenRequestContext m_tokenRequestContext;
|
||||
|
||||
public:
|
||||
explicit KeyVaultChallengeBasedAuthenticationPolicy(
|
||||
std::shared_ptr<Core::Credentials::TokenCredential const> credential,
|
||||
Core::Credentials::TokenRequestContext tokenRequestContext)
|
||||
: BearerTokenAuthenticationPolicy(credential, tokenRequestContext),
|
||||
m_tokenRequestContext(tokenRequestContext)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<HttpPolicy> Clone() const override
|
||||
{
|
||||
return std::make_unique<KeyVaultChallengeBasedAuthenticationPolicy>(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Core::Http::RawResponse> AuthorizeAndSendRequest(
|
||||
Core::Http::Request& request,
|
||||
Core::Http::Policies::NextHttpPolicy& nextPolicy,
|
||||
Core::Context const& context) const override
|
||||
{
|
||||
AuthenticateAndAuthorizeRequest(request, m_tokenRequestContext, context);
|
||||
return nextPolicy.Send(request, context);
|
||||
}
|
||||
|
||||
bool AuthorizeRequestOnChallenge(
|
||||
std::string const& challenge,
|
||||
Core::Http::Request& request,
|
||||
Core::Context const& context) const override
|
||||
{
|
||||
auto const scope = GetScope(challenge);
|
||||
if (scope.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ValidateChallengeResponse(scope, request.GetUrl().GetHost());
|
||||
|
||||
auto const tenantId = GetTenantId(GetAuthorization(challenge));
|
||||
m_tokenRequestContext.TenantId = tenantId;
|
||||
m_tokenRequestContext.Scopes = {scope};
|
||||
|
||||
AuthenticateAndAuthorizeRequest(request, m_tokenRequestContext, context);
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string TrimTrailingSlash(std::string const& s)
|
||||
{
|
||||
return (s.empty() || s.back() != '/') ? s : s.substr(0, s.size() - 1);
|
||||
}
|
||||
|
||||
static std::string GetScope(std::string const& challenge)
|
||||
{
|
||||
using Core::Credentials::_internal::AuthorizationChallengeParser;
|
||||
|
||||
auto resource
|
||||
= AuthorizationChallengeParser::GetChallengeParameter(challenge, "Bearer", "resource");
|
||||
|
||||
return !resource.empty()
|
||||
? (TrimTrailingSlash(resource) + "/.default")
|
||||
: AuthorizationChallengeParser::GetChallengeParameter(challenge, "Bearer", "scope");
|
||||
}
|
||||
|
||||
static std::string GetAuthorization(std::string const& challenge)
|
||||
{
|
||||
using Core::Credentials::_internal::AuthorizationChallengeParser;
|
||||
|
||||
auto authorization = AuthorizationChallengeParser::GetChallengeParameter(
|
||||
challenge, "Bearer", "authorization");
|
||||
|
||||
return !authorization.empty() ? authorization
|
||||
: AuthorizationChallengeParser::GetChallengeParameter(
|
||||
challenge, "Bearer", "authorization_uri");
|
||||
}
|
||||
|
||||
static bool TryParseUrl(std::string const& s, Core::Url& outUrl)
|
||||
{
|
||||
using Core::Url;
|
||||
try
|
||||
{
|
||||
outUrl = Url(s);
|
||||
}
|
||||
catch (std::out_of_range const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (std::invalid_argument const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ValidateChallengeResponse(std::string const& scope, std::string const& requestHost)
|
||||
{
|
||||
using Core::Url;
|
||||
using Core::Credentials::AuthenticationException;
|
||||
|
||||
Url scopeUrl;
|
||||
if (!TryParseUrl(scope, scopeUrl))
|
||||
{
|
||||
throw AuthenticationException("The challenge contains invalid scope '" + scope + "'.");
|
||||
}
|
||||
|
||||
auto const& scopeHost = scopeUrl.GetHost();
|
||||
|
||||
// Check whether requestHost.ends_with(scopeHost)
|
||||
auto const requestHostLength = requestHost.length();
|
||||
auto const scopeHostLength = scopeHost.length();
|
||||
|
||||
bool domainMismatch = requestHostLength < scopeHostLength;
|
||||
if (!domainMismatch)
|
||||
{
|
||||
auto const requestHostOffset = requestHostLength - scopeHostLength;
|
||||
for (size_t i = 0; i < scopeHostLength; ++i)
|
||||
{
|
||||
if (requestHost[requestHostOffset + i] != scopeHost[i])
|
||||
{
|
||||
domainMismatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (domainMismatch)
|
||||
{
|
||||
throw AuthenticationException(
|
||||
"The challenge resource '" + scopeHost + "' does not match the requested domain.");
|
||||
}
|
||||
}
|
||||
|
||||
static std::string GetTenantId(std::string const& authorization)
|
||||
{
|
||||
using Core::Url;
|
||||
using Core::Credentials::AuthenticationException;
|
||||
|
||||
if (!authorization.empty())
|
||||
{
|
||||
Url authorizationUrl;
|
||||
if (TryParseUrl(authorization, authorizationUrl))
|
||||
{
|
||||
auto const& path = authorizationUrl.GetPath();
|
||||
if (!path.empty())
|
||||
{
|
||||
auto const firstSlash = path.find('/');
|
||||
if (firstSlash == std::string::npos)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
else if (firstSlash > 0)
|
||||
{
|
||||
return path.substr(0, firstSlash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw AuthenticationException(
|
||||
"The challenge authorization URI '" + authorization + "' is invalid.");
|
||||
}
|
||||
};
|
||||
}}}} // namespace Azure::Security::KeyVault::_internal
|
|
@ -1,188 +1,10 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Key Vault Challenge-Based Authentication Policy.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/core/internal/credentials/authorization_challenge_parser.hpp>
|
||||
// This header file is left for compatibility purposes.
|
||||
// The name of this header is long, and may cause build error on Windows systems on some
|
||||
// installations, with long path and maximum path length of 260 characters.
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace _internal {
|
||||
/**
|
||||
* @brief Challenge-Based Authentication Policy for Key Vault.
|
||||
*
|
||||
*/
|
||||
class KeyVaultChallengeBasedAuthenticationPolicy final
|
||||
: public Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy {
|
||||
private:
|
||||
mutable Core::Credentials::TokenRequestContext m_tokenRequestContext;
|
||||
|
||||
public:
|
||||
explicit KeyVaultChallengeBasedAuthenticationPolicy(
|
||||
std::shared_ptr<Core::Credentials::TokenCredential const> credential,
|
||||
Core::Credentials::TokenRequestContext tokenRequestContext)
|
||||
: BearerTokenAuthenticationPolicy(credential, tokenRequestContext),
|
||||
m_tokenRequestContext(tokenRequestContext)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<HttpPolicy> Clone() const override
|
||||
{
|
||||
return std::make_unique<KeyVaultChallengeBasedAuthenticationPolicy>(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Core::Http::RawResponse> AuthorizeAndSendRequest(
|
||||
Core::Http::Request& request,
|
||||
Core::Http::Policies::NextHttpPolicy& nextPolicy,
|
||||
Core::Context const& context) const override
|
||||
{
|
||||
AuthenticateAndAuthorizeRequest(request, m_tokenRequestContext, context);
|
||||
return nextPolicy.Send(request, context);
|
||||
}
|
||||
|
||||
bool AuthorizeRequestOnChallenge(
|
||||
std::string const& challenge,
|
||||
Core::Http::Request& request,
|
||||
Core::Context const& context) const override
|
||||
{
|
||||
auto const scope = GetScope(challenge);
|
||||
if (scope.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ValidateChallengeResponse(scope, request.GetUrl().GetHost());
|
||||
|
||||
auto const tenantId = GetTenantId(GetAuthorization(challenge));
|
||||
m_tokenRequestContext.TenantId = tenantId;
|
||||
m_tokenRequestContext.Scopes = {scope};
|
||||
|
||||
AuthenticateAndAuthorizeRequest(request, m_tokenRequestContext, context);
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string TrimTrailingSlash(std::string const& s)
|
||||
{
|
||||
return (s.empty() || s.back() != '/') ? s : s.substr(0, s.size() - 1);
|
||||
}
|
||||
|
||||
static std::string GetScope(std::string const& challenge)
|
||||
{
|
||||
using Core::Credentials::_internal::AuthorizationChallengeParser;
|
||||
|
||||
auto resource
|
||||
= AuthorizationChallengeParser::GetChallengeParameter(challenge, "Bearer", "resource");
|
||||
|
||||
return !resource.empty()
|
||||
? (TrimTrailingSlash(resource) + "/.default")
|
||||
: AuthorizationChallengeParser::GetChallengeParameter(challenge, "Bearer", "scope");
|
||||
}
|
||||
|
||||
static std::string GetAuthorization(std::string const& challenge)
|
||||
{
|
||||
using Core::Credentials::_internal::AuthorizationChallengeParser;
|
||||
|
||||
auto authorization = AuthorizationChallengeParser::GetChallengeParameter(
|
||||
challenge, "Bearer", "authorization");
|
||||
|
||||
return !authorization.empty() ? authorization
|
||||
: AuthorizationChallengeParser::GetChallengeParameter(
|
||||
challenge, "Bearer", "authorization_uri");
|
||||
}
|
||||
|
||||
static bool TryParseUrl(std::string const& s, Core::Url& outUrl)
|
||||
{
|
||||
using Core::Url;
|
||||
try
|
||||
{
|
||||
outUrl = Url(s);
|
||||
}
|
||||
catch (std::out_of_range const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (std::invalid_argument const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ValidateChallengeResponse(std::string const& scope, std::string const& requestHost)
|
||||
{
|
||||
using Core::Url;
|
||||
using Core::Credentials::AuthenticationException;
|
||||
|
||||
Url scopeUrl;
|
||||
if (!TryParseUrl(scope, scopeUrl))
|
||||
{
|
||||
throw AuthenticationException("The challenge contains invalid scope '" + scope + "'.");
|
||||
}
|
||||
|
||||
auto const& scopeHost = scopeUrl.GetHost();
|
||||
|
||||
// Check whether requestHost.ends_with(scopeHost)
|
||||
auto const requestHostLength = requestHost.length();
|
||||
auto const scopeHostLength = scopeHost.length();
|
||||
|
||||
bool domainMismatch = requestHostLength < scopeHostLength;
|
||||
if (!domainMismatch)
|
||||
{
|
||||
auto const requestHostOffset = requestHostLength - scopeHostLength;
|
||||
for (size_t i = 0; i < scopeHostLength; ++i)
|
||||
{
|
||||
if (requestHost[requestHostOffset + i] != scopeHost[i])
|
||||
{
|
||||
domainMismatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (domainMismatch)
|
||||
{
|
||||
throw AuthenticationException(
|
||||
"The challenge resource '" + scopeHost + "' does not match the requested domain.");
|
||||
}
|
||||
}
|
||||
|
||||
static std::string GetTenantId(std::string const& authorization)
|
||||
{
|
||||
using Core::Url;
|
||||
using Core::Credentials::AuthenticationException;
|
||||
|
||||
if (!authorization.empty())
|
||||
{
|
||||
Url authorizationUrl;
|
||||
if (TryParseUrl(authorization, authorizationUrl))
|
||||
{
|
||||
auto const& path = authorizationUrl.GetPath();
|
||||
if (!path.empty())
|
||||
{
|
||||
auto const firstSlash = path.find('/');
|
||||
if (firstSlash == std::string::npos)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
else if (firstSlash > 0)
|
||||
{
|
||||
return path.substr(0, firstSlash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw AuthenticationException(
|
||||
"The challenge authorization URI '" + authorization + "' is invalid.");
|
||||
}
|
||||
};
|
||||
}}}} // namespace Azure::Security::KeyVault::_internal
|
||||
#include <azure/keyvault/shared/keyvault_challenge_based_auth.hpp>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <azure/storage/common/internal/file_io.hpp>
|
||||
#include <azure/storage/common/internal/reliable_stream.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/constants.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/constants.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -52,6 +52,7 @@ set(
|
|||
inc/azure/storage/common/internal/file_io.hpp
|
||||
inc/azure/storage/common/internal/reliable_stream.hpp
|
||||
inc/azure/storage/common/internal/shared_key_policy.hpp
|
||||
inc/azure/storage/common/internal/storage_bearer_token_auth.hpp
|
||||
inc/azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp
|
||||
inc/azure/storage/common/internal/storage_per_retry_policy.hpp
|
||||
inc/azure/storage/common/internal/storage_service_version_policy.hpp
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
class StorageBearerTokenAuthenticationPolicy final
|
||||
: public Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a Storage Bearer Token challenge authentication policy.
|
||||
*
|
||||
* @param credential An #Azure::Core::TokenCredential to use with this policy.
|
||||
* @param tokenRequestContext A context to get the token in.
|
||||
* @param enableTenantDiscovery Enables tenant discovery through the authorization challenge.
|
||||
*/
|
||||
explicit StorageBearerTokenAuthenticationPolicy(
|
||||
std::shared_ptr<const Azure::Core::Credentials::TokenCredential> credential,
|
||||
Azure::Core::Credentials::TokenRequestContext tokenRequestContext,
|
||||
bool enableTenantDiscovery)
|
||||
: BearerTokenAuthenticationPolicy(std::move(credential), tokenRequestContext),
|
||||
m_scopes(tokenRequestContext.Scopes), m_safeTenantId(tokenRequestContext.TenantId),
|
||||
m_enableTenantDiscovery(enableTenantDiscovery)
|
||||
{
|
||||
}
|
||||
|
||||
~StorageBearerTokenAuthenticationPolicy() override {}
|
||||
|
||||
std::unique_ptr<HttpPolicy> Clone() const override
|
||||
{
|
||||
return std::unique_ptr<HttpPolicy>(new StorageBearerTokenAuthenticationPolicy(*this));
|
||||
}
|
||||
|
||||
private:
|
||||
struct SafeTenantId
|
||||
{
|
||||
public:
|
||||
explicit SafeTenantId(std::string tenantId) : m_tenantId(std::move(tenantId)) {}
|
||||
|
||||
SafeTenantId(const SafeTenantId& other) : m_tenantId(other.Get()) {}
|
||||
|
||||
std::string Get() const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> lock(m_tenantIdMutex);
|
||||
return m_tenantId;
|
||||
}
|
||||
|
||||
void Set(const std::string& tenantId)
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex> lock(m_tenantIdMutex);
|
||||
m_tenantId = tenantId;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_tenantId;
|
||||
mutable std::shared_timed_mutex m_tenantIdMutex;
|
||||
};
|
||||
|
||||
std::vector<std::string> m_scopes;
|
||||
mutable SafeTenantId m_safeTenantId;
|
||||
bool m_enableTenantDiscovery;
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> AuthorizeAndSendRequest(
|
||||
Azure::Core::Http::Request& request,
|
||||
Azure::Core::Http::Policies::NextHttpPolicy& nextPolicy,
|
||||
Azure::Core::Context const& context) const override;
|
||||
|
||||
bool AuthorizeRequestOnChallenge(
|
||||
std::string const& challenge,
|
||||
Azure::Core::Http ::Request& request,
|
||||
Azure::Core::Context const& context) const override;
|
||||
};
|
||||
|
||||
}}} // namespace Azure::Storage::_internal
|
|
@ -3,78 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
// This header file is left for compatibility purposes.
|
||||
// The name of this header is long, and may cause build error on Windows systems on some
|
||||
// installations, with long path and maximum path length of 260 characters.
|
||||
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
class StorageBearerTokenAuthenticationPolicy final
|
||||
: public Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a Storage Bearer Token challenge authentication policy.
|
||||
*
|
||||
* @param credential An #Azure::Core::TokenCredential to use with this policy.
|
||||
* @param tokenRequestContext A context to get the token in.
|
||||
* @param enableTenantDiscovery Enables tenant discovery through the authorization challenge.
|
||||
*/
|
||||
explicit StorageBearerTokenAuthenticationPolicy(
|
||||
std::shared_ptr<const Azure::Core::Credentials::TokenCredential> credential,
|
||||
Azure::Core::Credentials::TokenRequestContext tokenRequestContext,
|
||||
bool enableTenantDiscovery)
|
||||
: BearerTokenAuthenticationPolicy(std::move(credential), tokenRequestContext),
|
||||
m_scopes(tokenRequestContext.Scopes), m_safeTenantId(tokenRequestContext.TenantId),
|
||||
m_enableTenantDiscovery(enableTenantDiscovery)
|
||||
{
|
||||
}
|
||||
|
||||
~StorageBearerTokenAuthenticationPolicy() override {}
|
||||
|
||||
std::unique_ptr<HttpPolicy> Clone() const override
|
||||
{
|
||||
return std::unique_ptr<HttpPolicy>(new StorageBearerTokenAuthenticationPolicy(*this));
|
||||
}
|
||||
|
||||
private:
|
||||
struct SafeTenantId
|
||||
{
|
||||
public:
|
||||
explicit SafeTenantId(std::string tenantId) : m_tenantId(std::move(tenantId)) {}
|
||||
|
||||
SafeTenantId(const SafeTenantId& other) : m_tenantId(other.Get()) {}
|
||||
|
||||
std::string Get() const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> lock(m_tenantIdMutex);
|
||||
return m_tenantId;
|
||||
}
|
||||
|
||||
void Set(const std::string& tenantId)
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex> lock(m_tenantIdMutex);
|
||||
m_tenantId = tenantId;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_tenantId;
|
||||
mutable std::shared_timed_mutex m_tenantIdMutex;
|
||||
};
|
||||
|
||||
std::vector<std::string> m_scopes;
|
||||
mutable SafeTenantId m_safeTenantId;
|
||||
bool m_enableTenantDiscovery;
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> AuthorizeAndSendRequest(
|
||||
Azure::Core::Http::Request& request,
|
||||
Azure::Core::Http::Policies::NextHttpPolicy& nextPolicy,
|
||||
Azure::Core::Context const& context) const override;
|
||||
|
||||
bool AuthorizeRequestOnChallenge(
|
||||
std::string const& challenge,
|
||||
Azure::Core::Http ::Request& request,
|
||||
Azure::Core::Context const& context) const override;
|
||||
};
|
||||
|
||||
}}} // namespace Azure::Storage::_internal
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp"
|
||||
|
||||
#include "azure/storage/common/internal/constants.hpp"
|
||||
#include "azure/storage/common/internal/storage_bearer_token_auth.hpp"
|
||||
|
||||
#include <azure/core/internal/credentials/authorization_challenge_parser.hpp>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/constants.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/constants.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/constants.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <azure/core/http/policies/policy.hpp>
|
||||
#include <azure/storage/common/crypt.hpp>
|
||||
#include <azure/storage/common/internal/shared_key_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_bearer_token_auth.hpp>
|
||||
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
|
||||
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
|
||||
|
|
Загрузка…
Ссылка в новой задаче