🧹 RemoveToken
Removes the token/credentials corresponding to the specified authentication type and domain from Composer's auth.json.
When to use
Use this when a token has expired, been revoked, or is no longer needed to access the corresponding repository, in order to avoid leaving invalid credentials in auth.json.
Signature
go
func (c *Composer) RemoveToken(authType string, domain string) errorParameters
| Parameter | Type | Description |
|---|---|---|
authType | string | Authentication type; one of: github-oauth, gitlab-oauth, bitbucket-oauth, bearer, http-basic |
domain | string | The domain whose credentials should be removed |
Return value
error: returns ErrInvalidAuthType when authType is not in the supported list; returns the corresponding error when reading or writing the file fails; nil on success.
Example
go
package main
import (
"errors"
"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)
}
// Remove the GitHub token
if err := comp.RemoveToken("github-oauth", "github.com"); err != nil {
if errors.Is(err, composer.ErrInvalidAuthType) {
log.Fatalf("unsupported authentication type")
}
log.Fatalf("remove token failed: %v", err)
}
fmt.Println("Token removed")
}Advanced
- The supported types do not include
gitlab-tokenandaws-access-key; these two must be removed manually viaGetAuthConfig+SaveAuthConfig. - To add tokens, see
AddGitHubToken,AddGitLabToken,AddBearerToken, andAddHTTPBasicAuth. - After removal, the configuration is written back to
auth.jsonimmediately (permission0600).