Python 使用用户名&;获取OAuth2令牌;passowrd授权类型

Python 使用用户名&;获取OAuth2令牌;passowrd授权类型,python,azure,adal,Python,Azure,Adal,我正在使用下面的adal库来获取Oauth2令牌(AAD) 以下代码确实有效,我可以获取我的令牌: 但在我的特定情况下,我希望能够通过提供用户名和密码(密码授予类型)获取令牌 有什么想法吗 谢谢,由于某种原因,该库在最新版本中删除了使用用户名密码执行身份验证的可能性 但是,请使用3.13.8.999此版本的Microsoft.IdentityModel.Clients.ActiveDirectory nuget软件包,该软件包不是最新的,但完全符合您的需要 然后就这样走 string ten

我正在使用下面的adal库来获取Oauth2令牌(AAD)

以下代码确实有效,我可以获取我的令牌:

但在我的特定情况下,我希望能够通过提供用户名和密码(密码授予类型)获取令牌

有什么想法吗


谢谢,

由于某种原因,该库在最新版本中删除了使用用户名密码执行身份验证的可能性

但是,请使用3.13.8.999此版本的Microsoft.IdentityModel.Clients.ActiveDirectory nuget软件包,该软件包不是最新的,但完全符合您的需要

然后就这样走

string tenantname = ConfigurationManager.AppSettings["ida:Tenant"];
string clientId = ConfigurationManager.AppSettings["ida:ClientID"];

string authority = $"https://login.microsoftonline.com/{tenantname}";
var authenticationContext = new AuthenticationContext(authority, null);

string username = $"{UserName}@{tenantname}";
var userCred = new UserPasswordCredential(username, Password);

 AuthenticationResult authResult = await   authenticationContext.AcquireTokenAsync(clientId, clientId, userCred);

希望这就是您想要的。

虽然没有很好的文档记录,但最新版本(0.4.4)中仍然提供用户/密码身份验证


请参阅以供参考:

谢谢,我可以在python中降低软件包版本吗?我想可以。但我不是python专家。。虽然我最近用c#做过。
context = adal.AuthenticationContext('https://login.microsoftonline.com/common')
context.acquire_token_with_username_password(
    'https://management.core.windows.net',
    'me@outlook.com',
    'password',
    '04b07795-8ddb-461a-bbee-02f9e1bf7b46')