Skip to content

🧹 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) error

Parameters

ParameterTypeDescription
authTypestringAuthentication type; one of: github-oauth, gitlab-oauth, bitbucket-oauth, bearer, http-basic
domainstringThe 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

Released under the MIT License