Skip to content

Instantly share code, notes, and snippets.

@ostark
Last active April 16, 2022 10:12
Show Gist options
  • Save ostark/e1c693c5fbb78d8398130891ffcbff91 to your computer and use it in GitHub Desktop.
Save ostark/e1c693c5fbb78d8398130891ffcbff91 to your computer and use it in GitHub Desktop.
Creates auth.json from ENV vars
<?php
/**
* Example: Oauth with Github token
* php make-auth-json.php github-oauth.github.com GITHUB_TOKEN
*
* Example: Basic auth for private satis repo
* php make-auth-json.php http-basic.nova.laravel.com NOVA_USERNAME NOVA_PASSWORD
*/
// remove script name
array_shift($argv);
$configArgs = [];
// Replace script arguments with ENV vars
foreach ($argv as $key) {
$configArgs[] = getenv($key) ?: $key;
}
// Pass modified arguments to 'composer config
shell_exec('composer config --auth ' . implode(' ', $configArgs));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment