使用StorageManagementClient的客户端密钥在服务/守护程序应用程序中获取MSAL令牌的步骤如下:
from azure.identity import ClientSecretCredential
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.storage.models import StorageAccount
tenant_id = '<your_tenant_id>'
client_id = '<your_client_id>'
client_secret = '<your_client_secret>'
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
subscription_id = '<your_subscription_id>'
storage_client = StorageManagementClient(credential, subscription_id)
token = credential.get_token('https://storage.azure.com/.default')
access_token = token.token
完整的代码示例:
from azure.identity import ClientSecretCredential
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.storage.models import StorageAccount
tenant_id = '<your_tenant_id>'
client_id = '<your_client_id>'
client_secret = '<your_client_secret>'
subscription_id = '<your_subscription_id>'
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
storage_client = StorageManagementClient(credential, subscription_id)
token = credential.get_token('https://storage.azure.com/.default')
access_token = token.token
这样,你就可以在服务/守护程序应用程序中使用StorageManagementClient的客户端密钥获取MSAL令牌了。
关于StorageManagementClient和MSAL的更多信息,你可以参考腾讯云的相关产品和文档:
领取专属 10元无门槛券
手把手带您无忧上云