【问题标题】:Composer install\update authentication failsComposer 安装\更新身份验证失败
【发布时间】:2014-04-23 17:41:07
【问题描述】:

当我尝试从我的私有存储库安装依赖项时,我收到以下错误:

> php.exe composer.phar update
Loading composer repositories with package information

  [RuntimeException]                                                           
  Failed to clone https://my.stash.repo/scm/lib/my-super-lib.git, could no  
  t read packages from it                                                      

  fatal: Authentication failed for 'https://my.stash.repo/scm/lib/my-super-lib.git/'                                                                   

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [packagesN]

Process finished with exit code 1 at 10:57:04.
Execution time: 1 996 ms.

相关composer.json部分如下:

   "require": {
        "php": ">=5.3.0",
        "scaytrase/my-super-lib": "1.1"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "https://my.stash.repo/scm/lib/my-super-lib.git"
        }
    ],

如果我直接设置用户名和密码

"url":  "https://username:password@my.stash.repo/scm/lib/my-super-lib.git"

composer 操作工作得很好。但我不想存储明文凭据。

有没有办法让作曲家每次都询问用户名和密码?

Repository 是 Atlassian Stash,前面有 https nginx(https 和 http 都经过测试)

Composer version 70a20ebcc19f1ea8ab0954a4fbdce208b30085e7 2014-03-12 16:07:58

编辑:

现在我自己执行git clone --mirror 来填充作曲家的缓存,然后像往常一样运行作曲家安装或作曲家更新(但它说它有时无法更新包信息)

code:

            $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
            if (0 !== $this->process->execute($command, $output)) {
                $output = $this->process->getErrorOutput();

                if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
                    throw new \RuntimeException('Failed to clone '.$this->url.', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                }

                throw new \RuntimeException('Failed to clone '.$this->url.', could not read packages from it' . "\n\n" .$output);
            }

manual git clone --mirror 工作正常并要求我提供凭据。但是作曲家(显然执行相同的命令) - 它没有。

EDIT2

这似乎是我正在使用的 PHP Storm 8 EAP 问题。最新的稳定版本需要在composer install 期间正确验证,但在composer update 期间不需要。

【问题讨论】:

    标签: php git composer-php bitbucket-server


    【解决方案1】:

    您可以使用这些 http 凭据设置加密文件,以便 git 从该加密文件中使用它们。
    这假设正在运行的 gpg 代理无法提供访问该凭据 gpg 加密文件所需的唯一密码。

    您将使用的网址将是:

    https://username@my.stash.repo/scm/lib/my-super-lib.git
    

    这允许 git 向其credential helper 询问正确的密码('username' 的密码)。

    具体示例请参见“Is there a way to skip password typing when using https://github”。

    【讨论】:

    • 这会导致使用 composer 出现不必要的困难。每台想要使用我的私有存储库的机器(甚至用户)都必须执行这些操作(因此显然我不想将用户名存储在 composer.json 中)。手动克隆所有依赖项和设置自动加载器会更容易,这会杀死所有作曲家功能。我希望有更简单的方法
    • @ScayTrase 我同意。这是为了集中访问(只有 one 用户必须输入他/她的凭据,或者,在我的回答中,gpg 密钥(每个会话一次,而不是每次)。情况就是这样如果所有用户都可以访问单个克隆的存储库并从那里运行作曲家。但在你的情况下这可能是不可能的。
    【解决方案2】:

    似乎是最新的 PhpStorm 8 EAP 134.1456 中的一个错误。 PhpStorm 7.1.3 与命令行类似的作曲家一起工作(行为相同)并执行composer install 很好(但不是composer update,但命令行也失败了)。

    我已经提交了bugreport

    编辑

    我给作曲家的错误报告已被this取代

    UPD2

    现在问题完全不现实。 Composer 正确处理身份验证,并要求将凭据存储在 COMPOSER_HOME/auth.json

    【讨论】:

    • 比我的回答更具体。 +1
    猜你喜欢
    • 2016-05-10
    • 2013-03-07
    • 2019-03-16
    • 2014-02-11
    • 1970-01-01
    • 2017-07-25
    • 2014-01-24
    相关资源
    最近更新 更多