gpt4 book ai didi

c# - Azure AD token 服务不响应refresh_token 和id_token

转载 作者:行者123 更新时间:2023-12-03 05:06:57 25 4
gpt4 key购买 nike

我正在尝试使用 Outlook REST API。我必须通过 Azure AD 进行身份验证,但我遇到了一个小问题。当我将授权代码交换为https://login.microsoftonline.com/common/oauth2/v2.0/token访问 token 响应时不包含我需要的refresh_token和id_token。我的代码发送请求是

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://login.microsoftonline.com/common/oauth2/v2.0/token");
req.Method = "POST";
req.ServicePoint.Expect100Continue = false;
req.UserAgent = "Example/1.0";
req.ContentType = "application/x-www-form-urlencoded";
using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
{
string data = "";
data += "grant_type=authorization_code";
data += "&code=" + Request.QueryString("code");
data += "&scope=" + HttpUtility.UrlEncode(string.Join(" ", scopes));
data += "&redirect_uri=" + HttpUtility.UrlEncode(redirectUri);
data += "&client_id=" + appId;
data += "&client_secret=" + appPassword;
sw.Write(data);
}
HttpWebResponse res = req.GetResponse();
using (StreamReader sr = new StreamReader(res.GetResponseStream()))
{
Response.ContentType = "application/json";
Response.Write(sr.ReadToEnd());
Response.End();
}

此代码的响应示例

{
"token_type": "Bearer",
"scope": "https://outlook.office.com/Calendars.Read https://outlook.office.com/Calendars.ReadWrite https://outlook.office.com/Mail.Read",
"expires_in": 3600,
"ext_expires_in": 0,
"access_token": "EwAYA+l3B/Qk ... IpfA0C"
}

我不知道我在做什么与 https://oauthplay.azurewebsites.net 不同因为响应包含所有属性。

最佳答案

对于刷新 token ,您必须在请求授权代码时请求 Offline_Access 范围,而对于 id_token,我想您需要 Profile 范围。 id_token 基本上供应用程序特定使用,只是为了验证该 token 仅由特定应用程序使用,并且没有其他应用程序代表其他应用程序使用该 token 。因此,请尝试请求可能为您提供刷新 token 的 offline_access 范围。

关于c# - Azure AD token 服务不响应refresh_token 和id_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39316806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com