If you are getting message below while trying to install private repositories with composer and want to avoid manual interaction, you can use this example.


Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+clone-php+2019-05-31+2137
to retrieve a token. It will be stored in "/root/.composer/auth.json" for future use by Composer.
Token (hidden):

Setup


You can omit "Token" and "Environment" steps below if you have previously completed both steps for any other projects.


composer.json


Assume that this is your composer.json file.


{
"repositories": [
{
"type": "git",
"url": "git@github.com:myprivate/repo.git",
"no-api": true #This is not compulsory
}
]
}

Obtaining token


  1. Navigate to GitHub's Personal Access Tokens page.

  2. Hit "Generate new token" button.

  3. Type something meaningful "Note", select "repo" as scope and hit "Generate token" button.

  4. Take a note of the token.

Environment preparation


Run command below on local PC.


export COMPOSER_AUTH='{"github-oauth":{"github.com":"AB8cd4cab23a9d5399934a7d7698d3fa74e9cfAB"}}'

docker-composer.yaml


Add entry below to docker-compose.yaml file as an environmental variable.


COMPOSER_AUTH: "${COMPOSER_AUTH}"

Test


If you run composer instal/update/require commands, you should not be asked to enter token.