🔐 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) errorParameters
| Parameter | Type | Description |
|---|---|---|
domain | string | Repository domain the authentication applies to |
username | string | Basic authentication username |
password | string | Basic 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
- Credentials are stored in the
AuthConfig.HTTPBasicmap returned byGetAuthConfig, with the value formatted asusername:password. - To remove credentials, use
RemoveTokenwith typehttp-basic. - Related methods:
AddGitHubToken,AddGitLabToken,AddBearerToken. - The
auth.jsonfile permission is0600, written bySaveAuthConfig.