Help us shape the future of Go! Take the 2026 Go Developer Survey

credential

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Names lists every credential, in the order a resolution tries and reports them.

Functions

func SetNameInContext

func SetNameInContext(ctx context.Context, name Name) context.Context

func WithCacheOf

func WithCacheOf(credential Credential, action func(cache reflect.Value)) (ok bool)

WithCacheOf reaches the optional Cache field of a credential struct, such as ApiKey, and holds the struct to what identityOf needs to copy it: Cache is a json-ignored pointer, and no other field is a pointer at all.

Types

type ApiKey

type ApiKey struct {
	Endpoint     xurl.URL
	ClientId     uuid.UUID `json:"client_id"`
	ClientSecret string    `json:"client_secret"`

	Cache *struct {
		Token jwt.JWT `json:"token,omitzero"`
	} `json:"-"`
}

func (*ApiKey) CachedToken

func (apiKey *ApiKey) CachedToken(_ context.Context, _ getWorkspaceFunc) (token jwt.JWT, found bool)

func (*ApiKey) Identity

func (apiKey *ApiKey) Identity() Identity

func (*ApiKey) RefreshCachedToken

func (apiKey *ApiKey) RefreshCachedToken(ctx context.Context, client http.Client, _ getWorkspaceFunc) error

type Credential

type Credential interface {
	// Identity identifies the credential, see Credentials.SetIdentity.
	Identity() Identity
	CachedToken(ctx context.Context, getWorkspace getWorkspaceFunc) (token jwt.JWT, found bool)
	// RefreshCachedToken re-mints the token, so a CachedToken call after it finds one.
	RefreshCachedToken(ctx context.Context, client http.Client, getWorkspace getWorkspaceFunc) error
}

type Credentials

type Credentials struct {
	ApiKey    *ApiKey    `json:"apiKey,omitempty"`
	Manual    *Manual    `json:"manual,omitempty"`
	OidcLogin *OidcLogin `json:"oidcLogin,omitempty"`
}

func (*Credentials) ByName

func (cs *Credentials) ByName(name Name) Credential

func (*Credentials) NameOf

func (cs *Credentials) NameOf(credential Credential) (out Name)

func (*Credentials) SetIdentity

func (cs *Credentials) SetIdentity(cred Credential)

type Identity

type Identity struct {
	Hash string
}

type Manual

type Manual struct {
	Endpoint xurl.URL `json:"endpoint"`
	Token    jwt.JWT  `json:"token"`
}

func (*Manual) CachedToken

func (manual *Manual) CachedToken(_ context.Context, _ getWorkspaceFunc) (jwt.JWT, bool)

func (*Manual) Identity

func (manual *Manual) Identity() Identity

func (*Manual) RefreshCachedToken

func (manual *Manual) RefreshCachedToken(_ context.Context, _ http.Client, _ getWorkspaceFunc) error

type Name

type Name string
const (
	// ApiKeyName mints a token from an API key id and secret.
	ApiKeyName Name = "apiKey"
	// ManualName sends an access token as it is.
	ManualName Name = "manual"
	// OidcLoginName logs a person in through a browser, so it resolves only when asked for by name.
	OidcLoginName Name = "oidcLogin"
)

func NameFromContext

func NameFromContext(ctx context.Context) (Name, error)

func (Name) String

func (n Name) String() string

type OidcLogin

type OidcLogin struct {
	Endpoint xurl.URL `json:"endpoint"`
	Issuer   xurl.URL `json:"issuer"`
	ClientId string   `json:"clientId"`
	Cache    *struct {
		RefreshToken string                  `json:"refreshToken"`
		ScopedTokens map[scope.Scope]jwt.JWT `json:"tokens,omitzero"`
	} `json:"-"`
}

func (*OidcLogin) CachedToken

func (oidcLogin *OidcLogin) CachedToken(ctx context.Context, getWorkspace getWorkspaceFunc) (token jwt.JWT, found bool)

func (*OidcLogin) Identity

func (oidcLogin *OidcLogin) Identity() Identity

func (*OidcLogin) RefreshCachedToken

func (oidcLogin *OidcLogin) RefreshCachedToken(ctx context.Context, client http.Client, getWorkspace getWorkspaceFunc) error

func (*OidcLogin) StoreLogin

func (oidcLogin *OidcLogin) StoreLogin(refreshToken string, token jwt.JWT)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL