Skip to content

🔐 AddHTTPBasicAuth ​

Adds HTTP Basic authentication credentials (username + password) to Composer's auth.json, used to access Composer repositories protected by Basic authentication.

When to use ​

Use when your private Composer repository is protected by HTTP Basic authentication (common with enterprise internal Nexus, Artifactory, or self-hosted repositories). Credentials are stored in the http-basic section of auth.json in username:password format.

Signature ​

go
func (c *Composer) AddHTTPBasicAuth(domain string, username string, password string) error

Parameters ​

ParameterTypeDescription
domainstringRepository domain the authentication applies to
usernamestringBasic authentication username
passwordstringBasic authentication password

Return value ​

error: Returns the corresponding error message when reading or writing auth.json fails; nil on success.

Example ​

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	// Add Basic auth for an internal repository
	if err := comp.AddHTTPBasicAuth("repo.intranet.com", "ci-user", "s3cret-pass"); err != nil {
		log.Fatalf("failed to add auth: %v", err)
	}

	fmt.Println("HTTP Basic auth written to auth.json")
}

Advanced ​

Released under the MIT License