auth

package
v3.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package auth contains various implementations for authenticating with Cerberus. These implementations can be used standalone from the main Cerberus client to get a login token or manage authentication without having to set up a full client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logout

func Logout(builtURL url.URL, headers http.Header) error

Logout takes a set of headers containing a token and a URL and logs out of Cerberus.

func Refresh

func Refresh(builtURL url.URL, headers http.Header) (*api.UserAuthResponse, error)

Refresh contains logic for refreshing a token against the API. Because all tokens can be refreshed this way, it is better to keep this in one place

Types

type Auth

type Auth interface {
	// GetToken should either return an existing token or perform all authentication steps
	// necessary to get a new token.
	GetToken(*os.File) (string, error)
	//IsAuthenticated should return whether or not there is a valid token. A valid token
	// is one that exists and is not expired
	IsAuthenticated() bool
	// Refresh uses the current valid token to retrieve a new one
	Refresh() error
	// Logout revokes the current token
	Logout() error
	// GetHeaders is a helper for any client using the authentication strategy.
	// It returns a basic set of headers asking for a JSON response and has
	// the authorization header set with the proper token
	GetHeaders() (http.Header, error)
	GetURL() *url.URL
	// GetExpiry either returns the expiry time of an existing token, or a zero-valued
	// time.Time struct and an error if a token doesn't exist
	GetExpiry() (time.Time, error)
}

The Auth interface describes the methods that all authentication providers must satisfy

type STSAuth added in v1.0.0

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

STSAuth uses AWS V4 signing authenticate to Cerberus.

func NewSTSAuth added in v1.0.0

func NewSTSAuth(cerberusURL, region string) (*STSAuth, error)

NewSTSAuth returns an STSAuth given a valid URL and region. Valid AWS credentials configured either by environment or through a credentials config file are also required.

func (*STSAuth) GetExpiry added in v1.2.0

func (a *STSAuth) GetExpiry() (time.Time, error)

GetExpiry returns the expiry time of the token if it already exists. Otherwise, it returns a zero-valued time.Time struct and an error.

func (*STSAuth) GetHeaders added in v1.0.0

func (a *STSAuth) GetHeaders() (http.Header, error)

GetHeaders returns the headers needed to authenticate against Cerberus. This will return an error if the token is expired or non-existent.

func (*STSAuth) GetToken added in v1.0.0

func (a *STSAuth) GetToken(*os.File) (string, error)

GetToken returns a token if it already exists and is not expired. Otherwise, it authenticates using the provided URL and region and then returns the token.

func (*STSAuth) GetURL added in v1.0.0

func (a *STSAuth) GetURL() *url.URL

GetURL returns the configured Cerberus URL.

func (*STSAuth) IsAuthenticated added in v1.0.0

func (a *STSAuth) IsAuthenticated() bool

IsAuthenticated returns whether or not the current token is set and is not expired.

func (*STSAuth) Logout added in v1.0.0

func (a *STSAuth) Logout() error

Logout deauthorizes the current valid token. This will return an error if the token is expired or non-existent.

func (*STSAuth) Refresh added in v1.0.0

func (a *STSAuth) Refresh() error

Refresh refreshes the current token by reauthenticating against the API.

type TokenAuth

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

TokenAuth uses a preexisting token to authenticate to Cerberus

func NewTokenAuth

func NewTokenAuth(cerberusURL, token string) (*TokenAuth, error)

NewTokenAuth takes a Cerberus URL and valid token and returns a new TokenAuth. There is no checking done on whether or not the token is valid, so the function expects the a valid token.

func (*TokenAuth) GetExpiry added in v1.3.0

func (t *TokenAuth) GetExpiry() (time.Time, error)

Always return zero-valued time.Time struct and a non-nil error

func (*TokenAuth) GetHeaders

func (t *TokenAuth) GetHeaders() (http.Header, error)

GetHeaders returns HTTP headers used for requests if the method is currently authenticated. Returns an error otherwise

func (*TokenAuth) GetToken

func (t *TokenAuth) GetToken(f *os.File) (string, error)

GetToken returns the token passed when creating the TokenAuth. Nil should be passed as the argument to the function. The argument exists for compatibility with the Auth interface

func (*TokenAuth) GetURL

func (t *TokenAuth) GetURL() *url.URL

GetURL returns the URL for cerberus

func (*TokenAuth) IsAuthenticated

func (t *TokenAuth) IsAuthenticated() bool

IsAuthenticated always returns true if there is a token. If Logout has been called, it will return false

func (*TokenAuth) Logout

func (t *TokenAuth) Logout() error

Logout logs the current token out and removes it from the authentication type

func (*TokenAuth) Refresh

func (t *TokenAuth) Refresh() error

Refresh attempts to refresh the token

Jump to

Keyboard shortcuts

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