Skip to content

Commit 69e5f1a

Browse files
Storage/feature parity (Azure#4869)
* add content type support on rename file. (Azure#4712) * Storage/STG74 Bearer Challenge (Azure#4743) * bearer challenge * Storage/STG78 OAuth Copy (Azure#4831) * OAuth Copy * add test for oauth copy * add test * fix conversation * fix conversation * update clang format * update test record * update test case * fix unit test cases * update recordings * recordings * fff * fix doc * CL * recording * fix typo * CL * recording * revert debug code --------- Co-authored-by: Jinming Hu <[email protected]>
1 parent b8d2301 commit 69e5f1a

39 files changed

+622
-62
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_62e8551aa8"
5+
"Tag": "cpp/storage_366c2de93d"
66
}

sdk/storage/azure-storage-blobs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
### Features Added
66

7+
- TenantId can now be discovered through the service challenge response, when using a TokenCredential for authorization.
8+
- A new property is now available on `BlobClientOptions` called `EnableTenantDiscovery`. If set to `true`, the client will attempt an initial unauthorized request to the service to prompt a challenge containing the tenantId hint.
9+
- Added a new field `SourceAuthorization` in options for copy operations, which can be used to specify authorization for copy source.
10+
711
### Breaking Changes
812

913
### Bugs Fixed

sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_options.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ namespace Azure { namespace Storage { namespace Blobs {
158158
* API version used by this client.
159159
*/
160160
std::string ApiVersion;
161+
162+
/**
163+
* Enables tenant discovery through the authorization challenge when the client is configured to
164+
* use a TokenCredential. When enabled, the client will attempt an initial un-authorized request
165+
* to prompt a challenge in order to discover the correct tenant for the resource.
166+
*/
167+
bool EnableTenantDiscovery = false;
161168
};
162169

163170
/**
@@ -580,6 +587,14 @@ namespace Azure { namespace Storage { namespace Blobs {
580587
* in this option. Default is to replace.
581588
*/
582589
Models::BlobCopySourceTagsMode CopySourceTagsMode;
590+
591+
/**
592+
* @brief Optional. Source authorization used to access the source file.
593+
* The format is: \<scheme\> \<signature\>
594+
* Only Bearer type is supported. Credentials should be a valid OAuth access token to copy
595+
* source.
596+
*/
597+
std::string SourceAuthorization;
583598
};
584599

585600
/**
@@ -949,6 +964,14 @@ namespace Azure { namespace Storage { namespace Blobs {
949964
* in this option. Default is to replace.
950965
*/
951966
Models::BlobCopySourceTagsMode CopySourceTagsMode;
967+
968+
/**
969+
* @brief Optional. Source authorization used to access the source file.
970+
* The format is: \<scheme\> \<signature\>
971+
* Only Bearer type is supported. Credentials should be a valid OAuth access token to copy
972+
* source.
973+
*/
974+
std::string SourceAuthorization;
952975
};
953976

954977
/**
@@ -997,6 +1020,14 @@ namespace Azure { namespace Storage { namespace Blobs {
9971020
* @brief Optional conditions that the source must meet to perform this operation.
9981021
*/
9991022
SourceAccessConditions;
1023+
1024+
/**
1025+
* @brief Optional. Source authorization used to access the source file.
1026+
* The format is: \<scheme\> \<signature\>
1027+
* Only Bearer type is supported. Credentials should be a valid OAuth access token to copy
1028+
* source.
1029+
*/
1030+
std::string SourceAuthorization;
10001031
};
10011032

10021033
/**
@@ -1282,6 +1313,14 @@ namespace Azure { namespace Storage { namespace Blobs {
12821313
* @brief Optional conditions that must be met to perform this operation.
12831314
*/
12841315
AppendBlobAccessConditions AccessConditions;
1316+
1317+
/**
1318+
* @brief Optional. Source authorization used to access the source file.
1319+
* The format is: \<scheme\> \<signature\>
1320+
* Only Bearer type is supported. Credentials should be a valid OAuth access token to copy
1321+
* source.
1322+
*/
1323+
std::string SourceAuthorization;
12851324
};
12861325

12871326
/**
@@ -1385,6 +1424,14 @@ namespace Azure { namespace Storage { namespace Blobs {
13851424
* @brief Optional conditions that the source must meet to perform this operation.
13861425
*/
13871426
SourceAccessConditions;
1427+
1428+
/**
1429+
* @brief Optional. Source authorization used to access the source file.
1430+
* The format is: \<scheme\> \<signature\>
1431+
* Only Bearer type is supported. Credentials should be a valid OAuth access token to copy
1432+
* source.
1433+
*/
1434+
std::string SourceAuthorization;
13881435
};
13891436

13901437
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ namespace Azure { namespace Storage { namespace Blobs {
216216
protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.Value().Algorithm.ToString();
217217
}
218218
protocolLayerOptions.EncryptionScope = m_encryptionScope;
219+
if (!options.SourceAuthorization.empty())
220+
{
221+
protocolLayerOptions.CopySourceAuthorization = options.SourceAuthorization;
222+
}
219223
return _detail::AppendBlobClient::AppendBlockFromUri(
220224
*m_pipeline, m_blobUrl, protocolLayerOptions, context);
221225
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <azure/storage/common/internal/file_io.hpp>
1717
#include <azure/storage/common/internal/reliable_stream.hpp>
1818
#include <azure/storage/common/internal/shared_key_policy.hpp>
19+
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
1920
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
2021
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
2122
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
@@ -87,8 +88,8 @@ namespace Azure { namespace Storage { namespace Blobs {
8788
Azure::Core::Credentials::TokenRequestContext tokenContext;
8889
tokenContext.Scopes.emplace_back(_internal::StorageScope);
8990
perRetryPolicies.emplace_back(
90-
std::make_unique<Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
91-
credential, tokenContext));
91+
std::make_unique<_internal::StorageBearerTokenAuthenticationPolicy>(
92+
credential, tokenContext, options.EnableTenantDiscovery));
9293
}
9394
perOperationPolicies.emplace_back(
9495
std::make_unique<_internal::StorageServiceVersionPolicy>(options.ApiVersion));
@@ -677,6 +678,10 @@ namespace Azure { namespace Storage { namespace Blobs {
677678
protocolLayerOptions.LegalHold = options.HasLegalHold;
678679
protocolLayerOptions.EncryptionScope = m_encryptionScope;
679680
protocolLayerOptions.CopySourceTags = options.CopySourceTagsMode;
681+
if (!options.SourceAuthorization.empty())
682+
{
683+
protocolLayerOptions.CopySourceAuthorization = options.SourceAuthorization;
684+
}
680685

681686
return _detail::BlobClient::CopyFromUri(*m_pipeline, m_blobUrl, protocolLayerOptions, context);
682687
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <azure/storage/common/crypt.hpp>
1414
#include <azure/storage/common/internal/constants.hpp>
1515
#include <azure/storage/common/internal/shared_key_policy.hpp>
16+
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
1617
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
1718
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
1819
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
@@ -169,9 +170,8 @@ namespace Azure { namespace Storage { namespace Blobs {
169170
{
170171
Azure::Core::Credentials::TokenRequestContext tokenContext;
171172
tokenContext.Scopes.emplace_back(_internal::StorageScope);
172-
tokenAuthPolicy = std::make_unique<
173-
Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
174-
credential, tokenContext);
173+
tokenAuthPolicy = std::make_unique<_internal::StorageBearerTokenAuthenticationPolicy>(
174+
credential, tokenContext, options.EnableTenantDiscovery);
175175
perRetryPolicies.emplace_back(tokenAuthPolicy->Clone());
176176
}
177177
perOperationPolicies.emplace_back(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <azure/storage/common/crypt.hpp>
1111
#include <azure/storage/common/internal/constants.hpp>
1212
#include <azure/storage/common/internal/shared_key_policy.hpp>
13+
#include <azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp>
1314
#include <azure/storage/common/internal/storage_per_retry_policy.hpp>
1415
#include <azure/storage/common/internal/storage_service_version_policy.hpp>
1516
#include <azure/storage/common/internal/storage_switch_to_secondary_policy.hpp>
@@ -82,9 +83,8 @@ namespace Azure { namespace Storage { namespace Blobs {
8283
{
8384
Azure::Core::Credentials::TokenRequestContext tokenContext;
8485
tokenContext.Scopes.emplace_back(_internal::StorageScope);
85-
tokenAuthPolicy = std::make_unique<
86-
Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
87-
credential, tokenContext);
86+
tokenAuthPolicy = std::make_unique<_internal::StorageBearerTokenAuthenticationPolicy>(
87+
credential, tokenContext, options.EnableTenantDiscovery);
8888
perRetryPolicies.emplace_back(tokenAuthPolicy->Clone());
8989
}
9090
perOperationPolicies.emplace_back(

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ namespace Azure { namespace Storage { namespace Blobs {
379379
}
380380
protocolLayerOptions.EncryptionScope = m_encryptionScope;
381381
protocolLayerOptions.CopySourceTags = options.CopySourceTagsMode;
382+
if (!options.SourceAuthorization.empty())
383+
{
384+
protocolLayerOptions.CopySourceAuthorization = options.SourceAuthorization;
385+
}
386+
382387
return _detail::BlockBlobClient::UploadFromUri(
383388
*m_pipeline, m_blobUrl, protocolLayerOptions, context);
384389
}
@@ -458,6 +463,11 @@ namespace Azure { namespace Storage { namespace Blobs {
458463
protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.Value().Algorithm.ToString();
459464
}
460465
protocolLayerOptions.EncryptionScope = m_encryptionScope;
466+
if (!options.SourceAuthorization.empty())
467+
{
468+
protocolLayerOptions.CopySourceAuthorization = options.SourceAuthorization;
469+
}
470+
461471
return _detail::BlockBlobClient::StageBlockFromUri(
462472
*m_pipeline, m_blobUrl, protocolLayerOptions, context);
463473
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ namespace Azure { namespace Storage { namespace Blobs {
233233
protocolLayerOptions.EncryptionAlgorithm = m_customerProvidedKey.Value().Algorithm.ToString();
234234
}
235235
protocolLayerOptions.EncryptionScope = m_encryptionScope;
236+
if (!options.SourceAuthorization.empty())
237+
{
238+
protocolLayerOptions.CopySourceAuthorization = options.SourceAuthorization;
239+
}
236240
return _detail::PageBlobClient::UploadPagesFromUri(
237241
*m_pipeline, m_blobUrl, protocolLayerOptions, context);
238242
}

sdk/storage/azure-storage-blobs/test/ut/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_executable (
1818
azure-storage-blobs-test
1919
append_blob_client_test.cpp
2020
append_blob_client_test.hpp
21+
bearer_token_test.cpp
2122
blob_batch_client_test.cpp
2223
blob_container_client_test.cpp
2324
blob_container_client_test.hpp

0 commit comments

Comments
 (0)