git 带有 oauth 访问令牌的 Github 克隆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42148841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Github clone with oauth access token
提问by Stephan-v
Inside a script I am trying to clone a Github repository with an oauth token.
在脚本中,我尝试使用 oauth 令牌克隆 Github 存储库。
According to this tutorial:
根据本教程:
https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth
https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth
I should be able to build a command for it like this:
我应该能够像这样为它构建一个命令:
git clone https://<token>@github.com/owner/repo.git
If I try this manually with a proper access token, it still asks for my password.
如果我使用适当的访问令牌手动尝试此操作,它仍会要求我输入密码。
If I try it on the commandline I am simply getting a repository not found
error.
如果我在命令行上尝试,我只会收到一个repository not found
错误。
The article is from 2012 and I cannot find any API documentation for this. So I am wondering if this still works.
这篇文章是 2012 年的,我找不到任何相关的 API 文档。所以我想知道这是否仍然有效。
回答by Stephan-v
I turned out to be a scope issue. I of course needed full repo
scope since I was trying to clone a private
repository.
我原来是一个范围问题。我当然需要完整的repo
范围,因为我试图克隆一个private
存储库。
It's a shame Github does not have some clearer error messages for these kind of things, but security wise I understand why.
遗憾的是,Github 没有针对此类事情提供更清晰的错误消息,但出于安全考虑,我理解为什么。
For anyone trying to figure out what is wrong when trying out something like this, I would suggest to create a personal access token with full access to everything:
对于在尝试这样的事情时试图找出问题所在的任何人,我建议创建一个具有对所有内容的完全访问权限的个人访问令牌:
settings > developer settings > personal access tokens > generate new token
设置 > 开发人员设置 > 个人访问令牌 > 生成新令牌
This way you can easily test if it is a scope issue by comparing your token with a personal access token that has access rights for everything.
通过这种方式,您可以通过将您的令牌与具有所有访问权限的个人访问令牌进行比较来轻松测试它是否是范围问题。
Thanks for anyone who still took the time to read this.
感谢任何仍然花时间阅读本文的人。
回答by t.ios
Do whatever works for you from these two choices
从这两个选择中做任何对你有用的事情
In your terminal
在你的终端
$ git clone your_repo_url
Username:your_token
Password:
$ git clone your_repo_url
Username:your_token
Password:
... there is no password
...没有密码
In your git client app
在您的 git 客户端应用程序中
i.e. Sourcetree, GitKraken, and the GitHub client.
即 Sourcetree、GitKraken 和 GitHub 客户端。
Enter your repo_url (obvsiously without the '$ git clone part')
输入您的 repo_url(显然没有“$ git clone 部分”)
Username:your_token
Password:
Username:your_token
Password:
... there is no password
...没有密码
ORi.e. in Sourcetree, open preferences and then go to advanced, enter the hostname (i.e. www.x.com) and userName (i.e. your_token)
或者,即在 Sourcetree 中,打开首选项,然后转到高级,输入主机名(即 www.x.com)和用户名(即 your_token)
回答by Insa
In .net core you can do in this way when dealing with Azure DevOps Repo:
在 .net core 中,您可以在处理 Azure DevOps Repo 时这样做:
public void CloneRepository()
{
var _gitURL = "URLofGitRemoteRepository";
var _userName = "PersonalAccessToken";
var _pswd = ""; //Keep it blank
var co = new CloneOptions();
co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = _userName, Password = _pswd };
Repository.Clone(_gitURL, filePath, co);
}