Skip to content

Commit 504d9f2

Browse files
Storage/STG91 Audience remove scope (Azure#5019)
* Audience remove scope * update record * update test * Update sdk/storage/azure-storage-common/src/storage_credential.cpp Co-authored-by: JinmingHu <[email protected]> --------- Co-authored-by: JinmingHu <[email protected]>
1 parent 5acdb5b commit 504d9f2

32 files changed

+111
-65
lines changed

sdk/storage/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "cpp",
44
"TagPrefix": "cpp/storage",
5-
"Tag": "cpp/storage_e44851d82e"
5+
"Tag": "cpp/storage_38dec59ffb"
66
}

sdk/storage/azure-storage-blobs/src/blob_client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ namespace Azure { namespace Storage { namespace Blobs {
8787
{
8888
Azure::Core::Credentials::TokenRequestContext tokenContext;
8989
tokenContext.Scopes.emplace_back(
90-
options.Audience.HasValue() ? options.Audience.Value().ToString()
91-
: Models::BlobAudience::PublicAudience.ToString());
90+
options.Audience.HasValue()
91+
? _internal::GetDefaultScopeForAudience(options.Audience.Value().ToString())
92+
: _internal::StorageScope);
9293
perRetryPolicies.emplace_back(
9394
std::make_unique<_internal::StorageBearerTokenAuthenticationPolicy>(
9495
credential, tokenContext, options.EnableTenantDiscovery));

sdk/storage/azure-storage-blobs/src/blob_container_client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ namespace Azure { namespace Storage { namespace Blobs {
170170
{
171171
Azure::Core::Credentials::TokenRequestContext tokenContext;
172172
tokenContext.Scopes.emplace_back(
173-
options.Audience.HasValue() ? options.Audience.Value().ToString()
174-
: Models::BlobAudience::PublicAudience.ToString());
173+
options.Audience.HasValue()
174+
? _internal::GetDefaultScopeForAudience(options.Audience.Value().ToString())
175+
: _internal::StorageScope);
175176
tokenAuthPolicy = std::make_unique<_internal::StorageBearerTokenAuthenticationPolicy>(
176177
credential, tokenContext, options.EnableTenantDiscovery);
177178
perRetryPolicies.emplace_back(tokenAuthPolicy->Clone());

sdk/storage/azure-storage-blobs/src/blob_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Azure { namespace Storage { namespace Blobs {
77

88
namespace Models {
9-
const BlobAudience BlobAudience::PublicAudience(Azure::Storage::_internal::StorageScope);
9+
const BlobAudience BlobAudience::PublicAudience(_internal::StoragePublicAudience);
1010
} // namespace Models
1111

1212
BlobQueryInputTextOptions BlobQueryInputTextOptions::CreateCsvTextOptions(

sdk/storage/azure-storage-blobs/src/blob_service_client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ namespace Azure { namespace Storage { namespace Blobs {
8383
{
8484
Azure::Core::Credentials::TokenRequestContext tokenContext;
8585
tokenContext.Scopes.emplace_back(
86-
options.Audience.HasValue() ? options.Audience.Value().ToString()
87-
: Models::BlobAudience::PublicAudience.ToString());
86+
options.Audience.HasValue()
87+
? _internal::GetDefaultScopeForAudience(options.Audience.Value().ToString())
88+
: _internal::StorageScope);
8889
tokenAuthPolicy = std::make_unique<_internal::StorageBearerTokenAuthenticationPolicy>(
8990
credential, tokenContext, options.EnableTenantDiscovery);
9091
perRetryPolicies.emplace_back(tokenAuthPolicy->Clone());

sdk/storage/azure-storage-blobs/test/ut/bearer_token_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace Azure { namespace Storage { namespace Test {
5151

5252
// With custom audience
5353
auto blobUrl = Azure::Core::Url(m_blockBlobClient->GetUrl());
54-
clientOptions.Audience = Blobs::Models::BlobAudience(
55-
blobUrl.GetScheme() + "://" + blobUrl.GetHost() + "/.default");
54+
clientOptions.Audience
55+
= Blobs::Models::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost());
5656
blobClient = Blobs::BlobClient(
5757
m_blockBlobClient->GetUrl(),
5858
std::make_shared<Azure::Identity::ClientSecretCredential>(

sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,14 +1456,14 @@ namespace Azure { namespace Storage { namespace Test {
14561456

14571457
// custom audience
14581458
auto containerUrl = Azure::Core::Url(containerClient.GetUrl());
1459-
clientOptions.Audience = Blobs::Models::BlobAudience(
1460-
containerUrl.GetScheme() + "://" + containerUrl.GetHost() + "/.default");
1459+
clientOptions.Audience
1460+
= Blobs::Models::BlobAudience(containerUrl.GetScheme() + "://" + containerUrl.GetHost());
14611461
containerClient
14621462
= Blobs::BlobContainerClient(m_blobContainerClient->GetUrl(), credential, clientOptions);
14631463
EXPECT_NO_THROW(containerClient.GetProperties());
14641464

14651465
// error audience
1466-
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com/.default");
1466+
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com");
14671467
containerClient
14681468
= Blobs::BlobContainerClient(m_blobContainerClient->GetUrl(), credential, clientOptions);
14691469
EXPECT_THROW(containerClient.GetProperties(), StorageException);

sdk/storage/azure-storage-blobs/test/ut/blob_service_client_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,14 @@ namespace Azure { namespace Storage { namespace Test {
514514

515515
// custom audience
516516
auto serviceUrl = Azure::Core::Url(serviceClient.GetUrl());
517-
clientOptions.Audience = Blobs::Models::BlobAudience(
518-
serviceUrl.GetScheme() + "://" + serviceUrl.GetHost() + "/.default");
517+
clientOptions.Audience
518+
= Blobs::Models::BlobAudience(serviceUrl.GetScheme() + "://" + serviceUrl.GetHost());
519519
serviceClient
520520
= Blobs::BlobServiceClient(m_blobServiceClient->GetUrl(), credential, clientOptions);
521521
EXPECT_NO_THROW(serviceClient.GetProperties());
522522

523523
// error audience
524-
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com/.default");
524+
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com");
525525
serviceClient
526526
= Blobs::BlobServiceClient(m_blobServiceClient->GetUrl(), credential, clientOptions);
527527
EXPECT_THROW(serviceClient.GetProperties(), StorageException);

sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,16 +2040,27 @@ namespace Azure { namespace Storage { namespace Test {
20402040
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20412041
EXPECT_NO_THROW(blockBlobClient.GetProperties());
20422042

2043+
// public audience
2044+
clientOptions.Audience = Blobs::Models::BlobAudience::PublicAudience;
2045+
blockBlobClient
2046+
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
2047+
EXPECT_NO_THROW(blockBlobClient.GetProperties());
2048+
20432049
// custom audience
20442050
auto blobUrl = Azure::Core::Url(blockBlobClient.GetUrl());
2045-
clientOptions.Audience = Blobs::Models::BlobAudience(
2046-
blobUrl.GetScheme() + "://" + blobUrl.GetHost() + "/.default");
2051+
clientOptions.Audience
2052+
= Blobs::Models::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost());
2053+
blockBlobClient
2054+
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
2055+
EXPECT_NO_THROW(blockBlobClient.GetProperties());
2056+
clientOptions.Audience
2057+
= Blobs::Models::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost() + "/");
20472058
blockBlobClient
20482059
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20492060
EXPECT_NO_THROW(blockBlobClient.GetProperties());
20502061

20512062
// error audience
2052-
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com/.default");
2063+
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com");
20532064
blockBlobClient
20542065
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20552066
EXPECT_THROW(blockBlobClient.GetProperties(), StorageException);

sdk/storage/azure-storage-common/inc/azure/storage/common/internal/constants.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Azure { namespace Storage { namespace _internal {
1111
constexpr static const char* HttpQuerySnapshot = "snapshot";
1212
constexpr static const char* HttpQueryVersionId = "versionid";
1313
constexpr static const char* StorageScope = "https://storage.azure.com/.default";
14+
constexpr static const char* StoragePublicAudience = "https://storage.azure.com";
1415
constexpr static const char* HttpHeaderDate = "date";
1516
constexpr static const char* HttpHeaderXMsVersion = "x-ms-version";
1617
constexpr static const char* HttpHeaderRequestId = "x-ms-request-id";

0 commit comments

Comments
 (0)