首页
文章
分类
系列
标签
关于
stackedit跳转github授权报错400解决
发布于: 2022-9-29   更新于: 2022-9-29   收录于: bug fix
本文字数: 204   阅读时长: 1 分钟   阅读量:

stackedit在弹出网页转到github授权界面的时候,弹出来了http400的错误,在你点授权之前,F12打开console,输入下边的JS code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
window.XMLHttpRequest =  class MyXMLHttpRequest extends window.XMLHttpRequest {
open(...args){
if(args[1].startsWith("https://api.github.com/user?access_token=")) {
  // apply fix as described by github
  // https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/#changes-to-make
  
  const segments = args[1].split("?");
  args[1] = segments[0]; // remove query params from url
  const token = segments[1].split("=")[1]; // save the token
  
  const ret = super.open(...args);
  
  this.setRequestHeader("Authorization", `token ${token}`); // set required header
  
  return ret;
}
else {
  return super.open(...args);
}
}
}

这段代码会重写stackedit的API请求,可以成功解决400的问题,成功授权。

Written with StackEdit.

赞赏
微信
取消