gitlab - 使用 access_token 推送到存储库 [英] gitlab - Push to a repository using access_token

查看:112
本文介绍了gitlab - 使用 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:

  1. 获取用户信息
  2. 为该用户创建一个 repo
  3. 将代码推送到这个仓库(使用 git push )

我已经成功获取用户信息(1)并创建repo(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

请注意,这会将访问令牌作为纯文本存储在 .gitconfig 文件中.为避免这种情况,您可以使用 git 凭证系统,为用户名"提供访问令牌名称.以及密码"的访问令牌.这应该以更安全的方式将凭证存储在 git 凭证系统中.

Note that this stores the access token as plain text in the .gitconfig 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屋!

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