36
42

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-10-31

たとえば下記のように、 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 認証の設定もかけるようですね。

36
42
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
42

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?