Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix duplicate sample tag in blob_samples_authentication.py #26929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())