我想驗證client_id,client_secret(使api調用Azure所需的所有基本憑據)。我想有一種方法是使用給定的client_id,client_secret等來生成令牌。
這是做這件事的正確方法嗎?如果是的話,我還需要什麼?我需要爲我的機器上傳證書嗎?如果不是,我該怎麼做?我可以在不爲我的機器生成證書的情況下驗證Azure憑證嗎?
def get_token(self, client_id, client_secret, endpoint_url, resource_url=None):
if not resource_url:
resource_url = 'https://management.core.windows.net/'
payload = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'resource': resource_url,
}
try:
response = requests.post(endpoint_url, data=payload).json()
token = response.get('access_token')
if token:
return token
except Exception as e:
LOG.exception(e.message)
你的問題並不清楚你的真實情況。但是,根據我的經驗,我認爲[文檔](https://docs.microsoft.com/en-us/rest/api/#create-the-request)介紹瞭如何創建請求來獲取訪問令牌來自Azure AD對您有所幫助。如果您可以改進描述,我想我可以回覆更多有用的細節。 –
我不是建議這是一個解決方案,只是想確保你知道來自MS的ADAL(https://github.com/AzureAD/azure-activedirectory-library-for-python)爲你做這件事。如果你知道它存在但不想因爲某種原因使用它,那很好。 –
@ PeterPan-MSFT我編輯了我的問題。 – user3837980