【发布时间】:2016-02-22 11:09:21
【问题描述】:
我正在尝试调用 Azure ARM Rest API 来创建资源组。我正在传递tenant_id、client_id 和client_secret 以获取稍后将用作授权标头的访问令牌。我的代码如下所示。应用程序ID是应用程序的客户端ID,应用程序秘密是选择持续时间后生成的密钥。
import adal
import requests
token_response = adal.acquire_token_with_client_credentials(
'https://login.microsoftonline.com/' + '<tenantId>',
'<ApplicationId>',
'<Application Secret>'
)
access_token = token_response.get('accessToken')
endpoint = 'https://management.azure.com/subscriptions/xxxx/resourcegroups/resourcename?api-version=2015-01-01'
headers = {"Authorization": 'Bearer ' + access_token}
json_output = requests.put(endpoint,headers=headers).json()
print json_output
但这给我带来了如下错误
{u'error': {u'message': u"The access token is from the wrong issuer 'https://sts
.windows.net/xxx/'. It must match the tenant 'h
ttps://sts.windows.net/xxx/' associated with th
is subscription. Please use the authority (URL) 'https://login.windows.net/xxx' to get the token. Note, if the subscription is
transferred to another tenant there is no impact to the services, but informatio
n about new tenant could take time to propagate (up to an hour). If you just tra
nsferred your subscription and see this error message, please try back later.",
u'code': u'InvalidAuthenticationTokenTenant'}}
此错误是什么意思,我是否传递了正确的凭据。如果我使用错误中提到的凭据,我会收到另一个错误,指出未找到带有提到的 client_id 的应用程序。
【问题讨论】:
-
您为“TenantId”传递的值是多少?
-
我正在传递 OAuth 2.0 授权端点中的字符串,它在 login.windows.net 之后
-
租户 ID 应该是 GUID 或类似
somevalue.onmicrosoft.com(本质上是您的 Azure AD 名称)的东西。是你提供的吗? -
@Gaurav,
https://manage.windowsazure.com/serco.onmicrosoft.com#Workspaces/ActiveDirectoryExtension/Directory/<Tenant ID GUID>/directoryQuickStart,这就是我要传递的内容。 -
@DSA - 是的,订阅将仅映射到一个活动目录,您必须使用映射到订阅的该目录的“租户 ID”。就我而言,我正在尝试使用未映射到我的订阅的目录。您可以更改设置并将订阅映射到您要使用的目录。
标签: python python-2.7 azure azure-active-directory