Skip to content

Commit 7274f25

Browse files
authored
[Storage] Fix Copy blob with Oauth failure (#14662) (#14667)
1 parent e86c589 commit 7274f25

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed copy blob fail with source context as Oauth [#14662]
22+
- `Start-AzStorageBlobCopy`
2123

2224
## Version 3.5.0
2325
* Fixed an issue that list account from resource group won't use nextlink

src/Storage/Storage/Common/StorageExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal static Uri GenerateUriWithCredentials(
197197
private static string GetBlobSasToken(CloudBlob blob)
198198
{
199199
if (null == blob.ServiceClient.Credentials
200-
|| blob.ServiceClient.Credentials.IsAnonymous)
200+
|| (blob.ServiceClient.Credentials.IsAnonymous && !blob.ServiceClient.Credentials.IsToken))
201201
{
202202
return string.Empty;
203203
}
@@ -225,8 +225,18 @@ private static string GetBlobSasToken(CloudBlob blob)
225225
{
226226
rootBlob = Util.GetBlobReference(blob.Uri, blob.ServiceClient.Credentials, blob.BlobType);
227227
}
228+
if (!blob.ServiceClient.Credentials.IsToken) // not oauth, generated normal sas
229+
{
230+
return rootBlob.GetSharedAccessSignature(policy);
231+
}
232+
else // oauth, generate identity sas
233+
{
234+
DateTimeOffset userDelegationKeyStartTime = DateTime.Now;
235+
DateTimeOffset userDelegationKeyEndTime = userDelegationKeyStartTime.AddMinutes(CopySASLifeTimeInMinutes) ;
236+
Azure.Storage.UserDelegationKey userDelegationKey = rootBlob.ServiceClient.GetUserDelegationKey(userDelegationKeyStartTime, userDelegationKeyEndTime);
228237

229-
return rootBlob.GetSharedAccessSignature(policy);
238+
return rootBlob.GetUserDelegationSharedAccessSignature(userDelegationKey, policy);
239+
}
230240
}
231241

232242
private static string GetBlobSasToken(BlobBaseClient blob, AzureStorageContext context)

0 commit comments

Comments
 (0)