使用令牌向 GitHub 进行身份验证 [英] Authenticate with GitHub using a token
问题描述
我正在尝试使用个人访问令牌向 GitHub 进行身份验证.在 GitHub 的帮助文件中,它声明使用 cURL 方法进行身份验证 (创建个人访问令牌).我已经尝试过这个,但我仍然无法推送到 GitHub.请注意,我正在尝试从未经身份验证的服务器(Travis CI)推送.
cd $HOMEgit config --global user.email "emailaddress@yahoo.com";git config --global user.name "username";curl -u "用户名:";https://github.com/username/ol3-1.gitgit clone --branch=gh-pages https://github.com/username/ol3-1.git gh-pagescd gh-pagesmkdir 构建测试cd 构建测试触摸asdf.asdfgit 添加 -f .git commit -m "Travis build $TRAVIS_BUILD_NUMBER 推送到 gh-pages";git push -fq origin gh-pages
此代码导致错误:
<块引用>远程:拒绝匿名访问 scuzzlebuzzle/ol3-1.git.
<块引用>
致命:https://github.com/scuzzlebuzzle/ol3-1.git/"的身份验证失败
你的 curl
命令完全错误.您应该使用以下内容
curl -H '授权:令牌'...
除此之外,如果存储库实际上是私有的,则它不会授权您的计算机克隆存储库.(然而,仔细一看,事实并非如此.)您通常会执行以下操作:
git clone https://scuzzlebuzzle:@github.com/scuzzlebuzzle/ol3-1.git --branch=gh-pages gh-pages
这会将您的凭据添加到克隆存储库时创建的远程.然而不幸的是,您无法控制 Travis 如何克隆您的存储库,因此您必须像这样编辑远程.
# 克隆后cd gh-pagesgit remote set-url origin https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git
这将修复您的项目以使用内置凭据的遥控器.
<块引用>警告:令牌具有读/写访问权限,应像密码一样对待.如果您在克隆或添加远程时将您的令牌输入到克隆 URL 中,Git 会将其以纯文本形式写入您的 .git/config 文件,这存在安全风险.
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 (Creating a personal access token). 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
This code causes the errors:
remote: Anonymous access to scuzzlebuzzle/ol3-1.git denied.
fatal: Authentication failed for 'https://github.com/scuzzlebuzzle/ol3-1.git/'"
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
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.
Warning: Tokens have read/write access and should be treated like passwords. If you enter your token into the clone URL when cloning or adding a remote,
Git writes it to your .git/config file in plain text, which is a security risk.
这篇关于使用令牌向 GitHub 进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!