auth

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionMaxAge = time.Hour * 24
)

Variables

View Source
var (
	// ErrorNoLocalCredsFound is returned if no client or user credentials were found and the invoker created the config with the option WithoutBrowserLogin
	ErrorNoLocalCredsFound = errors.New("there were no credentials found present on the machine")
)

Functions

func Write added in v0.24.0

func Write(cache Cache) error

Write saves HCP auth data in a common location in the home directory.

Types

type Browser added in v0.25.0

type Browser interface {
	GetTokenFromBrowser(context.Context, *oauth2.Config) (*oauth2.Token, error)
}

Browser implements the browser handler for the OAuth2 login flow.

type Cache added in v0.24.0

type Cache struct {
	// AccessToken is the bearer token used to authenticate to HCP.
	AccessToken string `json:"access_token,omitempty"`

	// RefreshToken is used to get a new access token.
	RefreshToken string `json:"refresh_token,omitempty"`

	// AccessTokenExpiry is when the access token will expire.
	AccessTokenExpiry time.Time `json:"access_token_expiry,omitempty"`

	// SessionExpiry is the session limit.
	SessionExpiry time.Time `json:"session_expiry,omitempty"`
}

func Read added in v0.24.0

func Read() (*Cache, error)

Read opens the saved HCP auth data and returns the token.

type MockSession added in v0.25.0

type MockSession struct{}

func (*MockSession) GetToken added in v0.25.0

func (s *MockSession) GetToken(ctx context.Context, conf *oauth2.Config) (*oauth2.Token, error)

GetToken returns some mock token with static data.

type Session added in v0.25.0

type Session interface {
	GetToken(ctx context.Context, conf *oauth2.Config) (*oauth2.Token, error)
}

Session handles managing a user's session.

type UserSession added in v0.25.0

type UserSession struct {
	NoBrowserLogin bool
	// contains filtered or unexported fields
}

UserSession implements the auth package's Session interface

func (*UserSession) GetToken added in v0.25.0

func (s *UserSession) GetToken(ctx context.Context, conf *oauth2.Config) (*oauth2.Token, error)

GetToken returns an access token obtained from either an existing session or new browser login.

Jump to

Keyboard shortcuts

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