I am writing codes for a Chrome extension that needs to access minus.com, which uses oAuth 2.0 for authentication, so I wrote a javascript file 'test.js', then included it in a HTML file 'test.html', then load 'test.html' in Chrome to test the javascript codes, which is used for the authentication.
The structure of the 'test.js' looks like this:
function Ajax(url, options) {
// some function content
// Sending data
if (options.method === "POST" && (options.params || options.binaryData)) {
if (options.binaryData) {
xhr.sendAsBinary(options.binaryData);
} else {
xhr.send(hashToQueryString(options.params));
}
} else {
xhr.send(null);
}
return xhr;
}
function refreshToken(refresh_token) {
var params = {
'grant_type': 'refresh_token',
'client_id': API_KEY,
'client_secret': API_SECRET,
'refresh_token': refresh_token,
'scope': 'read_all modify_all upload_new'
}
new Ajax("https://minus.com/oauth/token", {
params: params,
onSuccess: function(response) {
console.log(response.access_token);
},
onError: function(response) {
console.log('error: wrong_token');
}
});
}
refreshToken();
When I loaded the 'test.html' in Chrome to test 'test.js', it prompted an error in the console, saying "XMLHttpRequest cannot load https://minus.com/oauth/token?... Origin file:// is not allowed by Access-Control-Allow-Origin." I have tried to launch Chrome with the option "--allow-file-access-from-files" or "--disable-web-security", but it didn't solve the problem. However, if I commented the "Sending data" part in the "Ajax"function, there is no error.
Does anyone have ideas what's going on here?
Thanks!