我正在嘗試調用Azure ARM Rest API來創建資源組。我傳遞tenant_id,client_id和client_secret以獲取將在以後用作授權標頭的訪問令牌。我的代碼如下所示。應用程序ID是應用程序外的客戶端ID,應用程序密鑰是選擇持續時間後生成的密鑰。Azure Active Directory錯誤。訪問令牌來自錯誤的發佈者
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用戶授權端點,這是後弦https://login.windows.net – shwetha
租戶ID要麼是一個GUID或類似的東西'somevalue.onmicrosoft.com'(基本上是你的天青AD名稱)。你在提供嗎? –