Skip to content

Commit

Permalink
[Storage] Fix duplicate sample tag in blob_samples_authentication.py (
Browse files Browse the repository at this point in the history
Azure#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
  • Loading branch information
vincenttran-msft authored Oct 24, 2022
1 parent f89414f commit cdf13d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def auth_shared_access_signature(self):
# [END create_sas_token]

def auth_default_azure_credential(self):
# [START create_blob_service_client_oauth]
# [START create_blob_service_client_oauth_default_credential]
# Get a credential for authentication
# 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
# 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
Expand All @@ -137,7 +137,7 @@ def auth_default_azure_credential(self):
account_url=self.oauth_url,
credential=default_credential
)
# [END create_blob_service_client_oauth]
# [END create_blob_service_client_oauth_default_credential]

# Get account information for the Blob Service
account_info = blob_service_client.get_service_properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ async def auth_active_directory_async(self):
# [START create_blob_service_client_oauth]
# Get a token credential for authentication
from azure.identity.aio import ClientSecretCredential
token_credential = ClientSecretCredential(self.active_directory_tenant_id, self.active_directory_application_id,
self.active_directory_application_secret)
token_credential = ClientSecretCredential(
self.active_directory_tenant_id,
self.active_directory_application_id,
self.active_directory_application_secret
)

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

async def auth_default_azure_credential(self):
# [START create_blob_service_client_oauth_default_credential]
# Get a credential for authentication
# 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
# 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
# Alternately, one can specify the AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET to use the EnvironmentCredentialClass.
# The docs above specify all mechanisms which the defaultCredential internally support.
from azure.identity.aio import DefaultAzureCredential
default_credential = DefaultAzureCredential()

# Instantiate a BlobServiceClient using a token credential
from azure.storage.blob.aio import BlobServiceClient
blob_service_client = BlobServiceClient(
account_url=self.oauth_url,
credential=default_credential
)
# [END create_blob_service_client_oauth_default_credential]

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

async def main():
sample = AuthSamplesAsync()
# Uncomment the methods you want to execute.
await sample.auth_connection_string_async()
# await sample.auth_active_directory()
await sample.auth_active_directory_async()
await sample.auth_shared_access_signature_async()
await sample.auth_blob_url_async()
await sample.auth_default_azure_credential()

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

0 comments on commit cdf13d2

Please sign in to comment.