【发布时间】:2016-12-18 09:30:18
【问题描述】:
我正在尝试在 OneDrive for business 中进行身份验证并登录以获取访问令牌。
我已在 Azure Active Directory 中注册了我的应用程序,并获得了我的 client_Id 和我的 Client_Secret。基于OneDrive API Documentation,下一步是登录以获取将用于获取访问令牌的授权码。我能够成功获取代码,但下一步是带有以下参数的 POST:
发布https://login.microsoftonline.com/common/oauth2/token
内容类型:application/x-www-form-urlencoded
参数:
client_id:
redirect_uri:
client_secret:
code:
resource: The resource you want to access. ????
此时我将如何知道要访问的资源,尚不清楚为该参数发送什么值。
我将其留空并且收到“Access-Control-Allow-Origin”错误:
XMLHttpRequest 无法加载 https://login.microsoftonline.com/common/oauth2/token。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://localhost:23320' 不允许访问。响应的 HTTP 状态代码为 400。
这是我的代码:
var bodyInfo = {
client_id: {client_id},
redirect_uri: {redirect_uri},
client_secret: {client_secret},
code: {code},
grant_type: 'authorization_code',
resource:?????
};
$.ajax({
url: "https://login.microsoftonline.com/common/oauth2/token",
type: "POST",
data: bodyInfo,
success: function (data, textStatus, jqXHR) {
window.alert("Saved successfully!");
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
非常感谢任何帮助。
【问题讨论】:
标签: oauth office365 access-token onedrive