如何使用python中的ADAL,使用Azure区块链工作台的用户名和密码获取身份验证承载器?

2024-06-01 08:22:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试在Python的Azure区块链工作台上执行一些合同。我一直想不出如何使用这种方法。adal.acquire_token_用户名_密码()

我需要首先执行身份验证,以获取进行进一步API调用的承载器。 使用这个context.acquire_token_with_client_credentials(client_id,client_id,client_secret)它可以完美地工作 但是,上面的承载令牌与任何注册用户都没有关联。在

但是,要执行诸如添加新用户之类的管理任务,就必须获得管理帐户的承载者。所以我考虑使用acquire_token_with_username_password()来获得管理帐户的承载者。在

import adal
import swagger_client
from swagger_client.api_client import ApiClient
context = adal.AuthenticationContext("https://login.microsoftonline.com/kumarshobhit98outlook.onmicrosoft.com/",api_version=None)
client_id="c62087b9-cfed-4105-a9c2-4fd3953ceed5"
token = context.acquire_token_with_username_password(resource='https://graph.windows.net',username="shobhit@kumarshobhit98outlook.onmicrosoft.com",password="password",client_id=client_id)
print(token['accessToken'])

我想可能资源参数不正确。我不知道这个参数是什么意思。 这也是我得到的错误

^{pr2}$

我不明白为什么它要求一个客户端密码用户名密码方法的密码


Tags: 方法用户importcomclienttokenid密码
1条回答
网友
1楼 · 发布于 2024-06-01 08:22:36

however, to perform admin tasks like adding new users, one has to obtain the bearer for the admin account.

这是不对的。令牌权限与帐户无关,但与您授予应用程序的权限有关。例如,如果要调用add new user api。您将获得User.ReadWrite.All权限。在

enter image description here

转到Azure门户->Azure Active Directory->应用程序注册->查找您的应用程序->Api权限->添加权限->Microsoft Graph->应用程序权限->选择User.ReadWrite.All权限->授予管理员许可。在

I guess maybe the Resource parameter is incorrect. I do not know what the parameter means

这是目标web API(安全资源)的应用程序ID URI。它也可能是外部资源,如https://graph.microsoft.com。使用https://graph.windows.net设置它。那么您只能调用Azure AD graph api。在

I do not understand why is it asking for a client_secret for the username password method.

您需要将应用程序视为公共客户端。在

enter image description here

相关问题 更多 >