public string[] scopes1 = new string[]
{
"https://graph.microsoft.com/User.Read",
"https://graph.microsoft.com/User.ReadWrite",
"https://graph.microsoft.com/User.ReadBasic.All",
"https://graph.microsoft.com/Mail.Send",
"https://graph.microsoft.com/Calendars.ReadWrite",
"https://graph.microsoft.com/Mail.ReadWrite",
"https://graph.microsoft.com/Files.ReadWrite",
};
public async Task<string> GetAccessToken2()
{
string url = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?";//https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
// We want the response to be JSON.
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Build up the data to POST.
List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
postData.Add(new KeyValuePair<string, string>("client_id", appId));
postData.Add(new KeyValuePair<string, string>("client_secret", appPassword));
postData.Add(new KeyValuePair<string, string>("response_type", "code"));
postData.Add(new KeyValuePair<string, string>("response_mode", "query"));
// postData.Add(new KeyValuePair<string, string>("client_secret", appPassword));
//postData.Add(new KeyValuePair<string, string>("client_secret", appPassword));
postData.Add(new KeyValuePair<string, string>("redirect_uri", "http://localhost/5341/Home/AddC"));
postData.Add(new KeyValuePair<string, string>("Scope",string.Join(" ", scopes1)));// "openid offline_access https://graph.microsoft.com/mail.read"));
postData.Add(new KeyValuePair<string, string>("state", "12345"));
FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
// Post to the Server and parse the response.
HttpResponseMessage response = await client.PostAsync("Token", content);
string jsonString = await response.Content.ReadAsStringAsync();
object responseData = JsonConvert.DeserializeObject(jsonString);
// return the Access Token.
return ((dynamic)responseData).access_token;
}
}
{“error”:“invalid_scope”,“error_description”:“AADSTS70011:为输入参数”scope“提供的值无效。作用域 https://graph.microsoft.com/User.Read https://graph.microsoft.com/User.ReadWrite https://graph.microsoft.com/User.ReadBasic.All https://graph.microsoft.com/Mail.Send https://graph.microsoft.com/Calendars.ReadWrite https://graph.microsoft.com/Mail.ReadWrite https://graph.microsoft.com/Files.ReadWrite 无效。\r\n跟踪 ID: 17e465ac-9aca-4615-8021-f48ee8f00900\r\n相关 ID: 47a584ed-07ca-4a51-bdd1-8cb7364de3ee\r\n时间戳: 2017-09-15 12:39:26Z“,“error_codes”:[70011],“时间戳”:“2017-09-15 12:39:26Z”,“trace_id”:“17e465ac-9aca-4615-8021-f48ee8f00900”,“correlation_id”:“47a584ed-07ca-4a51-bdd1-8cb7364de3ee”}
https://login.microsoftonline.com/{{tenant_id}}/oaust2/令牌
删除v2.0版本并尝试一下。我得到的相同错误代码
“error_codes”:[70011],因此它可以解决您的问题
对的调用https://login.microsoftonline.com/common/oauth2/v2.0/authorize
是HTTP GET
,而不是POST。该回调函数接受授权代码并向
发出
。POST
https://login.microsoftonline.com/common/oauth2/v2.0/token
初始<code>GET</code>的原型是(新的可读性行):
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=[APPLICATION ID]&
response_type=code&
redirect_uri=[REDIRECT URI]&
scope=[SCOPE]
第二阶段发出
POST
。该原型是:
POST URL: https://login.microsoftonline.com/common/oauth2/v2.0/token
POST HEADER: Content-Type: application/x-www-form-urlencoded
POST BODY: grant_type=authorization_code&code=[AUTHORIZATION CODE]&
client_id=[APPLICATION ID]&client_secret=[PASSWORD]
&scope=[SCOPE]&redirect_uri=[REDIRECT URI]
也不是说这不是JSON,
Content-Type
是应用程序/x-www-form-urlen code
。
我不久前写了一篇文章,介绍了v2endpoint的授权代码流,您可能会发现它很有帮助:Microsoft v2endpoint入门
我是Python的初学者。我合并了两个之后,我试图用另一个列值更改一个列的'未分配'值。我不能那样做。如果我使用,那么我可以更改。 我从页面上抓取了一个表,然后修改了数据框中的数据。 pip安装lxml 这是我使用的代码。 我希望将邻域值更改为自治区值。 我得到了这个错误。 KeyError回溯(最近一次调用上次)/usr/local/lib/python3。6/数据包/熊猫/核心/索引/基础。p
URL类 来自服务器的最终响应:
我试图解决这个问题:第三个最大数量 但我犯了这个错误 第4行:Char 37:运行时错误:有符号整数溢出:-9223372036854775808-10不能在类型“long long”(solution.cpp)摘要中表示:UndefinedBehaviorSanitizer:undefined behavior prog_joined。cpp:13:37 这是我的代码 有人能告诉我这个错误到底意
然后,我创建了注释代码。 结果 原因:java.lang.StringIndexOutOfBoundsException:长度=0;指数=-6 说真的,我和这个代码斗争了7小时30分钟。