问题描述
这里是上下文:
这是场景:
问题出在这里
这是我的丑陋解决方法:
- 我使用了资源所有者密码凭据再次在后端登录用户。我的操作方式如下:当用户尝试创建在线会议时,系统提示他再次以HTML形式输入密码。该表单最终导致此方法恢复了Azure Active Directory访问令牌:
public async Task<string> GetTokenUser(string email,string password)
{
string token = null;
var clientID = "<ApplicationClientID>";
var secret = "<ApplicationSecret>";
var tenantID = HttpUtility.UrlEncode("<TenantDomain>");
var resource = HttpUtility.UrlEncode("https://graph.microsoft.com");
email= HttpUtility.UrlEncode(email);
password= HttpUtility.UrlEncode(password);
using (HttpClient client = new HttpClient())
{
var tokenEndpoint = @"https://login.windows.net/" + tenantID + "/oauth2/token";
var accept = "application/json";
client.DefaultRequestHeaders.Add("Accept",accept);
string postBody = @"resource=" + resource + @"
&client_id=" + clientID + @"
&client_secret=" + secret + @"
&grant_type=password
&username=" + email + @"
&password=" + password + "&scope=openid";
using (var response = await client.PostAsync(tokenEndpoint,new StringContent(postBody,Encoding.UTF8,"application/x-www-form-urlencoded")))
{
if (response.IsSuccessstatusCode)
{
var jsonresult = JObject.Parse(await response.Content.ReadAsstringAsync());
token = (string)jsonresult["access_token"];
}
}
}
return token;
}
这就是我需要的:
- 我需要找到一种更好的方法来在Azure Active Directory中登录用户,而不必再次提示密码。有什么方法可以告诉Azure Active Directory X用户通过电子邮件登录,而不必发送纯文本密码?
重要提示:我绝对不希望实现此目标,只要它可行且可靠。
编辑1:代码中的错字
解决方法
如果要访问Microsoft Graph,则必须进行Azure AD身份验证。
Create onlineMeeting仅支持委派权限,这意味着您必须遵循Get access on behalf of a user才能获得访问令牌。
因此,如果您不想使用ROPC流,则需要将AAD授权登录集成到您的项目中。
请按照此document进行操作。