我正在使用以下代码通过使用授权类型密码来获取访问令牌。我能够获得令牌,但是我在这里设置的作用域不会在重新操作中返回。在这里,我将范围设置为 Group.ReadWrite.All ,但我一直在使用范围 Calendars.ReadWrite.Shared email offline_access openid profile User.Read 进行响应。这里有什么问题,如何从这里设置范围?
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("resource", "https://graph.microsoft.com"),
new KeyValuePair<string, string>("username", "XXXXXXXX"),
new KeyValuePair<string, string>("password", "XXXXXXXX"),
new KeyValuePair<string, string>("client_id", "XXXXXXXXXXX"),
new KeyValuePair<string, string>("client_secret","XXXXXXXXXXXXXXX"),
new KeyValuePair<string, string>("scope","Group.ReadWrite.All")
});
string url = "https://login.microsoftonline.com/common/oauth2/token";
var result = await client.PostAsync(url, content);
string resultContent = await result.Content.ReadAsStringAsync();
return resultContent;
}