import request from 'superagent';
const self = this;
request
.post('https://github.com/login/oauth/access_token')
.set('Content-Type', 'multipart/form-data')
.query({
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
callback: 'http://127.0.0.1:3000/callback',
code,
state,
})
.end((err, res) => {
const token = res.body.access_token;
console.log(token);
self.setToken(token);
});
上面的代碼會給我這樣的錯誤
的XMLHttpRequest無法加載 https://github.com/login/oauth/access_token?client_id=112asdecf3805fdada12& ... 127.0.0.1%3A3000%2Fcallback &碼= 434ebd7bb98d9809bf6e & state = HelloWorld1234。 請求的 資源上沒有「Access-Control-Allow-Origin」標題。原因'http://127.0.0.1:3000'因此不允許 訪問。
我不知道爲什麼即使我已經註冊了github上和回調URL中的OAuth應用http://127.0.0.1:3000/callback
[瞭解CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) –