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

auth

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReauthenticationRequired = errors.New("reauthentication is required")

ErrReauthenticationRequired identifies an unusable grant that needs explicit user sign-in. Network failures and transient provider errors do not match it.

Functions

func IsMissingCredentials

func IsMissingCredentials(err error) bool

Types

type AuthorizationServerMetadata

type AuthorizationServerMetadata struct {
	Issuer                            string   `json:"issuer"`
	AuthorizationEndpoint             string   `json:"authorization_endpoint"`
	TokenEndpoint                     string   `json:"token_endpoint"`
	RevocationEndpoint                string   `json:"revocation_endpoint,omitempty"`
	RegistrationEndpoint              string   `json:"registration_endpoint"`
	ScopesSupported                   []string `json:"scopes_supported"`
	ResponseTypesSupported            []string `json:"response_types_supported"`
	GrantTypesSupported               []string `json:"grant_types_supported"`
	TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported"`
	CodeChallengeMethodsSupported     []string `json:"code_challenge_methods_supported"`
}

type CredentialStore

type CredentialStore interface {
	Load(profileName string) (Credentials, error)
	Save(profileName string, credentials Credentials) error
	Delete(profileName string) error
	UsingKeyring() bool
	Warning() string
}

type Credentials

type Credentials struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	TokenType    string    `json:"token_type"`
	Scope        string    `json:"scope"`
	ExpiresAt    time.Time `json:"expires_at"`
	ClientID     string    `json:"client_id"`
	ClientSecret string    `json:"client_secret,omitempty"`
	Issuer       string    `json:"issuer"`
	Resource     string    `json:"resource"`
}

type Discovery

type Discovery struct {
	Resource      ProtectedResourceMetadata   `json:"resource_metadata"`
	Authorization AuthorizationServerMetadata `json:"authorization_server_metadata"`
}

func Discover

func Discover(ctx context.Context, client *http.Client) (Discovery, error)

func DiscoverFrom

func DiscoverFrom(ctx context.Context, client *http.Client, resourceURL, expectedResource string) (Discovery, error)

type LoginOptions

type LoginOptions struct {
	Profile string
	NoOpen  bool
	URLSink func(string)
}

type LogoutResult

type LogoutResult struct {
	Profile string `json:"profile"`
	Revoked bool   `json:"revoked"`
	Warning string `json:"warning,omitempty"`
}

type ProfileStore

type ProfileStore interface {
	SnapshotProfile(string) (config.ProfileSnapshot, error)
	UpsertProfile(config.Profile) error
	RestoreProfile(config.ProfileSnapshot) error
}

type ProtectedResourceMetadata

type ProtectedResourceMetadata struct {
	Resource               string   `json:"resource"`
	AuthorizationServers   []string `json:"authorization_servers"`
	BearerMethodsSupported []string `json:"bearer_methods_supported"`
	ScopesSupported        []string `json:"scopes_supported"`
}

type Registration

type Registration struct {
	ClientID                string   `json:"client_id"`
	ClientSecret            string   `json:"client_secret,omitempty"`
	ClientIDIssuedAt        int64    `json:"client_id_issued_at"`
	ClientSecretExpiresAt   int64    `json:"client_secret_expires_at,omitempty"`
	ClientName              string   `json:"client_name"`
	RedirectURIs            []string `json:"redirect_uris"`
	GrantTypes              []string `json:"grant_types"`
	ResponseTypes           []string `json:"response_types"`
	TokenEndpointAuthMethod string   `json:"token_endpoint_auth_method"`
	Scope                   string   `json:"scope"`
}

type Service

type Service struct {
	Config      ProfileStore
	Credentials CredentialStore
	HTTPClient  *http.Client
	OpenBrowser func(string) error
	Now         func() time.Time
	Discover    func(context.Context, *http.Client) (Discovery, error)
}

func NewService

func NewService(cfg *config.Store, credentials CredentialStore) *Service

func (*Service) AccessToken

func (s *Service) AccessToken(ctx context.Context, profile string) (string, error)

func (*Service) Login

func (s *Service) Login(ctx context.Context, opts LoginOptions) (Status, error)

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, profile string) (LogoutResult, error)

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, profile string) (Status, error)

func (*Service) Status

func (s *Service) Status(profile string) (Status, error)

type Status

type Status struct {
	Profile       string    `json:"profile"`
	Authenticated bool      `json:"authenticated"`
	ExpiresAt     time.Time `json:"expires_at,omitempty"`
	Expired       bool      `json:"expired,omitempty"`
	Refreshable   bool      `json:"-"`
	Scope         string    `json:"scope,omitempty"`
	Issuer        string    `json:"issuer,omitempty"`
	Resource      string    `json:"resource,omitempty"`
	Storage       string    `json:"storage,omitempty"`
	Warning       string    `json:"warning,omitempty"`
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewCredentialStore

func NewCredentialStore(paths config.Paths, allowFileFallback bool) (*Store, error)

func (*Store) Delete

func (s *Store) Delete(profileName string) error

func (*Store) Load

func (s *Store) Load(profileName string) (Credentials, error)

func (*Store) Save

func (s *Store) Save(profileName string, credentials Credentials) error

func (*Store) UsingKeyring

func (s *Store) UsingKeyring() bool

func (*Store) Warning

func (s *Store) Warning() string

Jump to

Keyboard shortcuts

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