Outlook REST APIを使用しようとしています。私はAzure ADによって認証する必要があり、それに少し問題があります。 authorization code
をaccess token
に交換すると、https://login.microsoftonline.com/common/oauth2/v2.0/tokenという応答には、私が必要とするrefresh_tokenとid_tokenは含まれていません。私のコードの送信要求があっ応答がすべてのプロパティが含まれているので、私は、私はhttps://oauthplay.azurewebsites.netとは異なるやっているのか分からない、このコードAzure ADトークンサービスが応答を返さないrefresh_tokenおよびid_token
{
"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"
}
からの応答の
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();
}
例です。
リフレッシュトークンについては、認証コードを要求している間にオフラインアクセススコープを要求しなければならず、id_tokenの場合、プロファイルスコープが必要です。 id_tokenは、基本的にはアプリケーション固有のものです。トークンが特定のアプリケーションだけで使用されていることを確認し、他のアプリケーションが他のアプリケーションの代わりにトークンを使用していないことを確認します。 リフレッシュトークンを与える可能性のあるoffline_accessスコープをリクエストしてみてください。 –
ありがとうございます。できます。投稿できるのは答えですか?私はそれをマークします。 – Misaz