Skip to main content

Using Composer with Http Basic Auth (2nd try)

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

As I blogged recently we solved the HTTP Basic Auth problem with Composer / Satis by using expect. I still like the general idea but expect can be a bit tricky to configure. For those of you who are not happy with that solution this one might be a good alternative: As I helped out Manuel Lemos to create an Composer Installer for phpclasses.org packages he pointed out that the new Composer Plugin API might make it easier to extend Composer and offer authentication support. And yes he was right ;) As I had some spare time last weekend I extracted the code handling the authentication logic from his installer and created a separate plugin which can be found on github and packagist.org.

Using the plugin is rather simple, just follow these steps to set everything up. In your COMPOSER_HOME directory add a auth.json file which should look like this:

{
"config": {
"basic-auth": {
"satis.loc": {
"username": "my_username",
"password": "my_password"
}
}
}
}

The composer.json of your root project all you need is to require the AuthStore plugin as a dependency:

{
"name": "my/mywebproject",
"require": {
"bitexpert/composer-authstore-plugin": "*"
}
}

You can also install the plugin globally which might be the better alternative as globally installed plugins are loaded before local project plugins are loaded.
Whenever you run Composer now the plugin gets executed and reads the authentication information from the auth.json file and you do not neet to enter your credentials anymore when accessing a satis server or a repository that is procected by http basic auth.