Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
41
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

ComposerでGitHubのリポジトリをHTTPSで追加したときの認証設定

たとえば下記のように、 composer.json に GitHub で管理している自分のプライベートリポジトリを HTTPS で登録して composer install を実行すると、認証を求められるかと思います。

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/fivestar/privrepo"
        }
    ],
    "require": {
        "fivestar/privrepo": "dev-master"
    }
}
% composer install
Loading composer repositories with package information
Your GitHub credentials are required to fetch private repository metadata (https://github.com/fivestar/privrepo)
The credentials will be swapped for an OAuth token stored in /home/fivestar/.composer/auth.json, your password will not be stored
To revoke access to this token you can visit https://github.com/settings/applications
Username: fivestar
Password:

これだけならユーザー名/パスワードを入力すればいいんですけど2段階認証を有効にしてたりすると認証コードを求められたりするわけです。

Two-factor Authentication
You have been sent an SMS message with an authentication code to verify your identity.
Authentication Code: 

で、この表示がでたんですけど SMS がまったく飛んでこなくて、認証できないなーどうしようと調べていたら、GitHub のアクセストークンを Composer に設定すればいいようです。 (Composer ignores "github-oauth" configuration #1558)

まず GitHub で Settings > Personal access tokens から適当なアクセストークンを発行しておき、

image

以下のコマンドを実行します:

composer config --global github-oauth.github.com <access-token>

これで無事 composer install ができるようになります。ちなみにこの auth.json 、 BASIC 認証の設定もかけるようですね。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
41
Help us understand the problem. What are the problem?