Skip to content

Commit cdf13d2

Browse files
[Storage] Fix duplicate sample tag in blob_samples_authentication.py (#26929)
* Fixed duplicate sample tag, added missing sample to async + unify samples to match more closely * Add function call to newest sample in async * Removed uncomment comment
1 parent f89414f commit cdf13d2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def auth_shared_access_signature(self):
122122
# [END create_sas_token]
123123

124124
def auth_default_azure_credential(self):
125-
# [START create_blob_service_client_oauth]
125+
# [START create_blob_service_client_oauth_default_credential]
126126
# Get a credential for authentication
127127
# Default Azure Credentials attempt a chained set of authentication methods, per documentation here: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
128128
# For example user (who must be an Azure Event Hubs Data Owner role) to be logged in can be specified by the environment variable AZURE_USERNAME
@@ -137,7 +137,7 @@ def auth_default_azure_credential(self):
137137
account_url=self.oauth_url,
138138
credential=default_credential
139139
)
140-
# [END create_blob_service_client_oauth]
140+
# [END create_blob_service_client_oauth_default_credential]
141141

142142
# Get account information for the Blob Service
143143
account_info = blob_service_client.get_service_properties()

sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ async def auth_active_directory_async(self):
8484
# [START create_blob_service_client_oauth]
8585
# Get a token credential for authentication
8686
from azure.identity.aio import ClientSecretCredential
87-
token_credential = ClientSecretCredential(self.active_directory_tenant_id, self.active_directory_application_id,
88-
self.active_directory_application_secret)
87+
token_credential = ClientSecretCredential(
88+
self.active_directory_tenant_id,
89+
self.active_directory_application_id,
90+
self.active_directory_application_secret
91+
)
8992

9093
# Instantiate a BlobServiceClient using a token credential
9194
from azure.storage.blob.aio import BlobServiceClient
@@ -111,13 +114,34 @@ async def auth_shared_access_signature_async(self):
111114
)
112115
# [END create_sas_token]
113116

117+
async def auth_default_azure_credential(self):
118+
# [START create_blob_service_client_oauth_default_credential]
119+
# Get a credential for authentication
120+
# Default Azure Credentials attempt a chained set of authentication methods, per documentation here: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
121+
# For example user (who must be an Azure Event Hubs Data Owner role) to be logged in can be specified by the environment variable AZURE_USERNAME
122+
# Alternately, one can specify the AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET to use the EnvironmentCredentialClass.
123+
# The docs above specify all mechanisms which the defaultCredential internally support.
124+
from azure.identity.aio import DefaultAzureCredential
125+
default_credential = DefaultAzureCredential()
126+
127+
# Instantiate a BlobServiceClient using a token credential
128+
from azure.storage.blob.aio import BlobServiceClient
129+
blob_service_client = BlobServiceClient(
130+
account_url=self.oauth_url,
131+
credential=default_credential
132+
)
133+
# [END create_blob_service_client_oauth_default_credential]
134+
135+
# Get account information for the Blob Service
136+
account_info = blob_service_client.get_service_properties()
137+
114138
async def main():
115139
sample = AuthSamplesAsync()
116-
# Uncomment the methods you want to execute.
117140
await sample.auth_connection_string_async()
118-
# await sample.auth_active_directory()
141+
await sample.auth_active_directory_async()
119142
await sample.auth_shared_access_signature_async()
120143
await sample.auth_blob_url_async()
144+
await sample.auth_default_azure_credential()
121145

122146
if __name__ == '__main__':
123147
asyncio.run(main())

0 commit comments

Comments
 (0)