I am trying to authenticate and to sign to in OneDrive for business in order to get an access token.
I have registered my application in Azure Active Directory and I have got my client_Id and my Client_Secret. Base on the OneDrive API Documentation the next step is to login to get the authorization code that will be used to get the access token. I am able to get the code successfully but the next step is a POST with the following parameters:
POST https://login.microsoftonline.com/common/oauth2/token
Content-Type: application/x-www-form-urlencoded
Parameters:
client_id:
redirect_uri:
client_secret:
code:
resource: The resource you want to access. ????
At this point how I am going to know the resource to access, it is not clear what value to send for this parameter.
I am leaving it empty and I am getting a "Access-Control-Allow-Origin" error:
XMLHttpRequest cannot load https://login.microsoftonline.com/common/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:23320' is therefore not allowed access. The response had HTTP status code 400.
This is my code:
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) {
}
});
I would really appreciate any help.