gitlab-使用access_token推送到存储库 [英] gitlab - Push to a repository using access_token
问题描述
我实现了oauth2网络流程,以便从我的应用程序用户那里获取access_token.使用access_token,我想执行以下操作:
I implemented the oauth2 web flow in order to get access_token from users of my app. With the access_token, I would like to do the following actions:
- 获取用户信息
- 为此用户创建一个仓库
- 将代码推送到此仓库(使用git push)
我已经成功获取用户信息(1)并创建了一个仓库(2)
I already successfully get the user information(1) and create a repo(2)
问题是我无法推送代码(3),出现未经授权"错误.
The problem is I can't push code (3), I got "Unauthorized" error.
我运行的命令:
git remote add origin https://gitlab-ci-token<mytoken>@gitlab.com/myuser/myrepo.git
git push origin master
推荐答案
您应该这样做
git remote add origin https://<access-token-name>:<access-token>@gitlab.com/myuser/myrepo.git
请注意,这会将访问令牌以纯文本格式存储在.git\config
文件中.为了避免这种情况,您可以使用git凭证系统,为"username"用户名提供访问令牌名称.以及用于密码"的访问令牌. 应该以更安全的方式将凭据存储在git凭据系统中.
Note that this stores the access token as plain text in the .git\config
file. To avoid this you can use the git credential system, providing the access token name for "username" and the access token for "password". This should store the credentials in the git credential system in a more secure way.
这篇关于gitlab-使用access_token推送到存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!