小编Anu*_*ngh的帖子

Azure:访问令牌是从错误的受众或资源中获取的

尝试创建一个简单的任务来列出Azure门户中的所有资源.我按照给定URL中的方向并成功接收了令牌.

http://azure-sdk-for-python.readthedocs.org/en/latest/resourcemanagement.html#authentication

但是,使用令牌和superscription_id的组合,我收到以下错误.

错误:

azure.common.AzureHttpError: {"error"{"code":"AuthenticationFailed","message":"The access token has been obtained from wrong audience or resource '00000002-0000-0000-c000-000000000000'. It should exactly match (including forward slash) with one of the allowed audiences 'https://management.core.windows.net/','https://management.azure.com/'."}}  
Run Code Online (Sandbox Code Playgroud)

我在Active目录中创建了一个应用程序,并为Windows Active Directory分配了所有权限

以下是获取令牌的代码:

def get_token_from_client_credentials(endpoint, client_id, client_secret):
    payload = {
        'grant_type': 'client_credentials',
        'client_id': client_id,
        'client_secret': client_secret
        # 'resource': 'https://management.core.windows.net/',
    }
    response = requests.post(endpoint, data=payload).json()
    return response['access_token']

auth_token = get_token_from_client_credentials(endpoint='https://login.microsoftonline.com/11111111111-1111-11111-1111-111111111111/oauth2/token',
             client_id='22222222-2222-2222-2222-222222222222',
             client_secret='test/one/year/secret/key',
Run Code Online (Sandbox Code Playgroud)

尝试在以下代码中使用此标记:

def get_list_resource_groups(access_token, subscription_id):
    cred = SubscriptionCloudCredentials(subscription_id, access_token)
    resource_client = ResourceManagementClient(cred)
    resource_group_list = resource_client.resource_groups.list(None)
    rglist = resource_group_list.resource_groups …
Run Code Online (Sandbox Code Playgroud)

python azure azure-resource-manager

5
推荐指数
2
解决办法
4606
查看次数

标签 统计

azure ×1

azure-resource-manager ×1

python ×1