Share via


Azure Authorization-bibliotek för Python

Hanterings-API

pip install azure-mgmt-authorization

Skapa hanteringsklienten

Följande kod skapar en instans av hanteringsklienten.

Du måste ange vilken subscription_id som kan hämtas från din prenumerationslista.

Mer information om hur du hanterar Azure Active Directory-autentisering med Python SDK och hur du skapar en Credentials instans finns i Autentisering för resurshantering.

from azure.mgmt.authorization import AuthorizationManagementClient
from azure.common.credentials import UserPassCredentials

# Replace this with your subscription id
subscription_id = '33333333-3333-3333-3333-333333333333'

# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
    'user@domain.com',	# Your user
    'my_password' 		# Your password
)

authorization_client = AuthorizationManagementClient(
    credentials,
    subscription_id
)

Kontrollera behörigheter för en resursgrupp

Följande kod kontrollerar behörigheter i en viss resursgrupp. Information om hur du skapar eller hanterar resursgrupper finns i Resurshantering.

from azure.mgmt.redis.models import Sku, RedisCreateOrUpdateParameters

group_name = 'myresourcegroup'
permissions = self.authorization_client.permissions.list_for_resource_group(
    group_name
)
# permissions is a iterable of Permissions instances