Currently, I am in the process of developing a Chrome extension that requires access to a site called minus.com, which implements oAuth 2.0 for authentication. To facilitate this, I have created a javascript file named 'test.js' and integrated it into an HTML file called 'test.html'. Subsequently, I loaded 'test.html' in Chrome to test the javascript code that handles the authentication process.
The structure of the 'test.js' file is as follows:
function Ajax(url, options) {
// contents of the function
// Data transmission
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();
Upon loading 'test.html' in Chrome to test 'test.js', an error appeared in the console stating "XMLHttpRequest cannot load ?... Origin file:// is not allowed by Access-Control-Allow-Origin." I attempted to resolve this issue by launching Chrome with the options "--allow-file-access-from-files" or "--disable-web-security", but unfortunately, the problem persisted. Interestingly, commenting out the "Data transmission" segment in the "Ajax" function led to the elimination of the error.
It would be greatly appreciated if anyone could provide insights into what may be causing this issue.
Thank you!