Integrated Composer Usage
How to use Pantheon Secrets with Pantheon's Integrated Composer.
Using secrets with Integrated Composer
Mechanism 1: OAuth composer authentication (recommended)
If your Composer-based dependency is private, and the repository supports OAuth authentication, storing your token as a secret in the Pantheon Secrets API is a simpler way to allow access to those private repositories.
Generate a GitHub token. The GitHub token must have all "repo" permissions selected.
Note: Check the repo box that selects all child boxes. Do not check all child boxes individually as this does not set the correct permissions.
Set the secret value to the token via terminus:
terminus secret:site:set <site> github-oauth.github.com <github_token> --type=composer --scope=ic
Add your private repository to the
repositories
section ofcomposer.json
:{ "type": "vcs", "url": "https://github.com/your-organization/your-repository-name" }
Your repository should contain a
composer.json
that declares a package name in itsname
field. It should specify atype
likewordpress-plugin
ordrupal-module
for example. For these instructions, we will assume your package name isyour-organization/your-package-name
.Require the package defined by your private repository's
composer.json
by either adding a new record to therequire
section of the site'scomposer.json
or with acomposer require
command:composer require your-organization/your-package-name
Commit your changes and push to Pantheon.
Generate a GitLab token. Ensure that
read_repository
scope is selected for the token.Set the secret value to the token via Terminus:
terminus secret:site:set <site> gitlab-oauth.gitlab.com <gitlab_token> --type=composer --scope=ic
Add your private repository to the
repositories
section ofcomposer.json
:{ "type": "vcs", "url": "https://gitlab.com/your-group/your-repository-name" }
Your repository should contain a
composer.json
that declares a package name in itsname
field. It should specify atype
likewordpress-plugin
ordrupal-module
for example. For these instructions, we will assume your package name isyour-organization/your-package-name
.Require the package defined by your private repository's
composer.json
by either adding a new record to therequire
section of the site'scomposer.json
or with acomposer require
command:composer require your-group/your-package-name
Commit your changes and push to Pantheon.
Generate a Bitbucket OAuth consumer. Ensure that Read repositories permission is selected for the consumer. Set the consumer as private and put a (dummy) callback URL.
Set the secret value to the consumer info via Terminus:
terminus secret:site:set <site> bitbucket-oauth.bitbucket.org "<consumer_key> <consumer_secret>" --type=composer --scope=ic
Add your private repository to the
repositories
section ofcomposer.json
:{ "type": "vcs", "url": "https://bitbucket.org/your-organization/your-repository-name" }
Your repository should contain a
composer.json
that declares a package name in itsname
field. It should specify atype
likewordpress-plugin
ordrupal-module
for example. For these instructions, we will assume your package name isyour-organization/your-package-name
.Require the package defined by your private repository's
composer.json
by either adding a new record to therequire
section of the site'scomposer.json
or with acomposer require
command:composer require your-organization/your-package-name
Commit your changes and push to Pantheon.
Mechanism 2: HTTP Basic Authentication
In the case where you have a Composer dependency that only supports HTTP Basic Authentication, you may create a COMPOSER_AUTH json
and make it available via the COMPOSER_AUTH
environment variable if you have multiple private repositories on multiple private domains.
Composer has the ability to read private repository access information from the environment variable: COMPOSER_AUTH
. The COMPOSER_AUTH
variables must be in a specific JSON format.
Format example:
#!/bin/bash
read -e COMPOSER_AUTH_JSON <<< {
"http-basic": {
"github.com": {
"username": "my-username1",
"password": "my-secret-password1"
},
"repo.example2.org": {
"username": "my-username2",
"password": "my-secret-password2"
},
"private.packagist.org": {
"username": "my-username2",
"password": "my-secret-password2"
}
}
}
EOF
terminus secret:site:set ${SITE_NAME} COMPOSER_AUTH ${COMPOSER_AUTH_JSON} --type=env --scope=ic