【发布时间】:2021-05-13 15:59:39
【问题描述】:
我正在使用以下指南为我的应用设置 Oauth2。
https://docs.microsoft.com/en-us/graph/auth-v2-user
这是 /authorize URL 获取请求,工作正常:
GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectUri}&response_mode=query&scope=offline_access%20user.read%20files.readwrite
然后,我从 redirectUri 获取代码并 POST 到这个 URL:
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
返回一个 access_token 和一个 refresh_token。
但是,每当我需要刷新令牌时,Graph API 只会返回一个新的 access_token。 我正在使用 axios 和 qs:
//get new tokens
const scope = "Files.ReadWrite";
const data = qs.stringify({
client_id: clientId,
client_secret: clientSecret,
grant_type: "refresh_token",
redirect_uri: redirectUri,
scope: scope,
refresh_token: oneDriveRefreshToken
});
const headers = {
"Content-Type": "application/x-www-form-urlencoded",
};
const response = await axios.post(tokenEndpoint, data, headers);
const json = response.data;
functions.logger.debug(json.access_token); //ok
functions.logger.debug(json.refresh_token); //undefined
据我了解,授权代码流以及“offline_access”范围应该使您能够在调用 /token 端点时获得新的刷新令牌
【问题讨论】:
-
尝试将
scope改为:const scope = "Files.ReadWrite offline_access";
标签: azure-active-directory microsoft-graph-api