我正在尝试进行身份验证并签入OneDrive for business以获取访问令牌。使用OneDrive API获取访问令牌
我已经在Azure Active Directory中注册了我的应用程序,并获得了我的client_Id和我的Client_Secret。基于OneDrive API Documentation,下一步是登录以获取将用于获取访问令牌的授权码。我能够顺利拿到代码,但下一步是具有以下参数的POST:
POST https://login.microsoftonline.com/common/oauth2/token
内容类型:应用程序/ x-WWW窗体-urlencoded
参数:
client_id:
redirect_uri:
client_secret:
code:
resource: The resource you want to access. ????
至此我怎么知道要访问的资源,目前还不清楚为这个参数发送什么值。
我离开它空的,我收到了“访问控制允许来源”错误:
的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) {
}
});
我真的很感激任何帮助。
任何想法如何使用办公室的发现API?我找不到一个明确的例子。 –
[这里](https://msdn.microsoft.com/en-us/office/office365/api/discovery-service-rest-operations)是发现服务REST API参考的文档。 –