使用令牌向GitHub进行身份验证 [英] Authenticate with GitHub using a token

查看:295
本文介绍了使用令牌向GitHub进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用个人访问令牌向GitHub进行身份验证.在github上的帮助文件中,它声明使用cURL方法进行身份验证( https://help.github.com/articles/creating-an-access-token-for-command-line-use ).我已经尝试过了,但是我仍然无法推送到GitHub.请注意,我正在尝试从未经身份验证的服务器(Travis-CI)进行推送.

I am trying to authenticate with GitHub using a personal access token. In the help files at github, it states to use the cURL method to authenticate (https://help.github.com/articles/creating-an-access-token-for-command-line-use). I have tried this, but I still cannot push to GitHub. Please note, I am trying to push from an unauthenticated server (Travis-CI).

cd $HOME
git config --global user.email "emailaddress@yahoo.com"
git config --global user.name "username"

curl -u "username:<MYTOKEN>" https://github.com/username/ol3-1.git
git clone --branch=gh-pages https://github.com/username/ol3-1.git gh-pages

cd gh-pages
mkdir buildtest
cd buildtest
touch asdf.asdf

git add -f .
git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to gh-pages"
git push -fq origin gh-pages

此代码会导致错误:

远程:匿名访问scuzzlebuzzle/ol3-1.git被拒绝.

remote: Anonymous access to scuzzlebuzzle/ol3-1.git denied.

致命:' https://github.com/scuzzlebuzzle/ol3-1的身份验证失败.git/'"

推荐答案

您的curl命令完全错误.您应该使用以下

Your curl command is entirely wrong. You should be using the following

curl -H 'Authorization: token <MYTOKEN>' ...

此外,这实际上并不授权您的计算机克隆存储库(如果它是私有的). (但是,看看它表示不是.)通常,您需要执行以下操作:

That aside, that doesn't authorize your computer to clone the repository if in fact it is private. (Taking a look, however, indicates that it is not.) What you would normally do is the following:

git clone https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git --branch=gh-pages gh-pages

这会将您的凭据添加到克隆存储库时创建的远程目录中.但是不幸的是,您无法控制Travis如何克隆您的存储库,因此您必须像这样编辑遥控器.

That will add your credentials to the remote created when cloning the repository. Unfortunately, however, you have no control over how Travis clones your repository, so you have to edit the remote like so.

# After cloning
cd gh-pages
git remote set-url origin https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git

这将使您的项目修复为使用具有内置凭据的遥控器.

That will fix your project to use a remote with credentials built in.

警告:令牌具有读/写访问权限,应像对待密码一样对待.如果您在克隆或添加遥控器时在克隆URL中输入令牌,则Git writes it to your .git/config file in plain text, which is a security risk.

这篇关于使用令牌向GitHub进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆