如何基于浏览器获取包含权限的GitHub Token?

cuimingda

Cui Mingda

Posted on August 8, 2021

如何基于浏览器获取包含权限的GitHub Token?

参照Hexo这篇文档,准备将Hexo生成的网站,通过Github Actions部署到Github Pages,在git push的时候,提示下面错误。

Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (8/8), 957 bytes | 957.00 KiB/s, done.
Total 8 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 1 local object.
To https://github.com/cuimingda/cuimingda.github.io.git
 ! [remote rejected] source -> source (refusing to allow an OAuth App to create or update workflow `.github/workflows/pages.yml` without `workflow` scope)
error: failed to push some refs to 'https://github.com/cuimingda/cuimingda.github.io.git'
Enter fullscreen mode Exit fullscreen mode

查了一下,貌似git默认会从系统中获取github的token,而这个token是没有oauth权限的,一种解决方法是在GitHub上生成一个新的token,并更新到系统中。

但是更好的办法,是在需要获取token的时候,通过浏览器直接获取当前登录用户的token。

为了实现这个效果,需要安装一个组件,安装过程会需要输入管理员密码:

brew tap microsoft/git
brew install --cask git-credential-manager-core
Enter fullscreen mode Exit fullscreen mode

安装这个组件以后,再次执行git push,这个时候就会让你选择到底是跳转到浏览器认证,还是输入用户名密码认证,不管哪种方式,都可以获取到包含正确作用域的token,之后就一切正常了。

References

💖 💪 🙅 🚩
cuimingda
Cui Mingda

Posted on August 8, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related