auth

package
v1.41.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Password         = AuthType("password")
	Refresh          = AuthType("refresh")
	ClientCredential = AuthType("clientcred")
	Certificate      = AuthType("cert")
	FederatedThyOne  = AuthType("thy-one")
	FederatedAws     = AuthType("aws")
	FederatedAzure   = AuthType("azure")
	FederatedGcp     = AuthType("gcp")
	Oidc             = AuthType("oidc")
)

Types of supported authentication.

View Source
const (
	GcpGceAuth = "gce"
	GcpIamAuth = "iam"
)

Variables

View Source
var KeyfileNotFoundError = errors.NewS("failed to find the encryption key") // trunk-ignore(golangci-lint/gochecknoglobals)

KeyfileNotFoundError is a global error variable is of type *ApiError, not regular error.

Functions

func Decrypt

func Decrypt(data, key string) (string, error)

Decrypt takes encrypted data and the key and attempts to decrypt the data back into plain text.

func EncipherPassword

func EncipherPassword(plaintext string) (string, error)

EncipherPassword takes in a plaintext password and returns the encrypted version of it. This is a higher-level function that looks up an encryption key found in the default path for tokens and key files. It then tries to encrypt the password using the encryption key, which must exist.

func Encrypt

func Encrypt(key, data string) (string, string, error)

Encrypt returns a cipher text encrypted with AES-256, a key to decrypt, and any error that might have occurred.

func GetAudience

func GetAudience() string

func GetCurrentIdentity

func GetCurrentIdentity() (string, error)

func GetEncryptionKey

func GetEncryptionKey(fileName string) ([]byte, error)

GetEncryptionKey attempts to fetch and return the encryption key stored in fileName. If it does not find the key, it generates and returns a slice of random bytes as a new encryption key.

func GetEncryptionKeyFilename

func GetEncryptionKeyFilename(tenant string, user string) string

GetEncryptionKeyFilename creates and returns a filename for an encryption key given the tenant name and user name.

func ParseMetadataIdentityResponse

func ParseMetadataIdentityResponse(resp *http.Response) (string, error)

func ParseSubjectFromToken

func ParseSubjectFromToken(accessToken string) (string, error)

func StorePassword

func StorePassword(fileName, data string) (string, string, error)

StorePassword takes a fileName in which it tries to find an encryption key. It also receives data to encrypt (password). It returns the encrypted data, key for later decryption, and any error that might have occurred.

Types

type AuthType

type AuthType string

AuthType is the type of authentication.

type Authenticator

type Authenticator interface {
	GetToken() (*TokenResponse, *errors.ApiError)
	WipeCachedTokens() error
}

Authenticator is the interface used for authentication funcs.

func NewAuthenticator

func NewAuthenticator(store store.Store, client requests.Client) Authenticator

NewAuthenticator returns a new authenticator.

func NewAuthenticatorDefault

func NewAuthenticatorDefault() Authenticator

NewAuthenticatorDefault gets a new default authenticator.

type GcpClient

type GcpClient struct{}

func (*GcpClient) GetJwtToken

func (c *GcpClient) GetJwtToken(authType string) (string, error)

type TokenResponse

type TokenResponse struct {
	Token        string    `json:"accessToken"`
	TokenType    string    `json:"tokenType"`
	ExpiresIn    int64     `json:"expiresIn"`
	RefreshToken string    `json:"refreshToken"`
	Granted      time.Time `json:"granted"`
}

func (*TokenResponse) IsNil

func (r *TokenResponse) IsNil() bool

Jump to

Keyboard shortcuts

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