通过HTTPS将Composer与私有GitHub存储库结合使用 [英] Using a Composer with private GitHub repos over HTTPS

查看:67
本文介绍了通过HTTPS将Composer与私有GitHub存储库结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有许多私有存储库,我们希望将它们包含在使用Composer的PHP应用程序中. composer.json 文件包含以下条目,该条目定义了我们的第一个私有存储库:

We have a number of private repositories which we would like to include in a PHP application using Composer. The composer.json file contains this entry which defines our first private repository:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/vendor/package.git"
    }
]

然后,我们需要像正常情况一样的存储库:

We then require the repository like normal:

"require": {
    "vendor/package": "~1.0.0"
}

我要做的唯一一件额外的事情就是在GitHub上设置一个私有访问令牌,并将其存储在作曲家的 auth.json 文件中.看起来像:

The only extra thing I have done is set a private access token up on GitHub and store it in composers auth.json file. That looks like:

{
    "github-oauth": {
        "github.com": "<my_access_token>"
    }
}

一切似乎都已经正确设置,Composer可以使用访问令牌通过HTTPS通过GitHub访问GitHub,但是我们遇到了如下错误:

Everything looks like it's been setup correctly for Composer to access GitHub via HTTPS with the access token, but we're getting errors which look like this:

[RuntimeException]
Failed to clone https://github.com/vendor/package.git via https protocols, aborting.
 - https://github.com/vendor/package.git
   Cloning into bare repository '/home/vagrant/.composer/cache/vcs/https---github.com-vendor-package.git'...
   remote: Invalid username or password.
   fatal: Authentication failed for 'https://github.com/vendor/package.git/'

访问令牌是有效的,因为我使用它来超过您经常看到的超出速率限制消息,并且该令牌在GitHub上显示为最近使用过.

The access token is valid, because I have used it to get past the rate limit exceeded message you often see and it's showing up on GitHub as being recently used.

我们错过了这里的某个步骤吗?理想情况下,我们只想使用Composer和GitHub来执行此操作.不需要设置Satis或Trojan.从文档看来,我们应该能够使用个人访问令牌访问我们的私有存储库.

Have we missed out a step here? Ideally we'd like to do this using just Composer and GitHub. Setting up Satis or Trojan isn't something we're keen on having to do. It seems from the documentation that we should be able to access our private repos using a personal access token.

推荐答案

使用以下语法代替HTTPS:

Instead of HTTPS, use this syntax:

"repositories": [
    {
        "type": "vcs",
        "url": "git@github.com:vendor/package.git"
    }
]

我们经常成功地使用它.

We use this quite often, successfully.

请参阅此处: https://getcomposer.org/doc/05-repositories.md#using-private-repositories

这篇关于通过HTTPS将Composer与私有GitHub存储库结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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