auth

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: Apache-2.0 Imports: 19 Imported by: 59

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractExpiryFromAccessToken

func ExtractExpiryFromAccessToken(token string) (int, error)

Extracts the expiry from an access token, in seconds

func ExtractUsernameFromAccessToken

func ExtractUsernameFromAccessToken(token string) (string, error)

func IsEncrypted

func IsEncrypted(buffer []byte) (bool, error)

func SshAuthentication

func SshAuthentication(url, sshKeyPath, sshPassphrase string) (sshAuthHeaders map[string]string, newUrl string, err error)

Types

type CommonConfigFields

type CommonConfigFields struct {
	Url                 string                  `json:"-"`
	User                string                  `json:"-"`
	Password            string                  `json:"-"`
	ApiKey              string                  `json:"-"`
	AccessToken         string                  `json:"-"`
	TokenRefreshHandler TokenRefreshHandlerFunc `json:"-"`
	ClientCertPath      string                  `json:"-"`
	ClientCertKeyPath   string                  `json:"-"`
	Version             string                  `json:"-"`
	SshUrl              string                  `json:"-"`
	SshKeyPath          string                  `json:"-"`
	SshPassphrase       string                  `json:"-"`
	SshAuthHeaders      map[string]string       `json:"-"`
	TokenMutex          sync.Mutex
}

func (*CommonConfigFields) AuthenticateSsh

func (ds *CommonConfigFields) AuthenticateSsh(sshKeyPath, sshPassphrase string) error

func (*CommonConfigFields) CreateHttpClientDetails

func (ds *CommonConfigFields) CreateHttpClientDetails() httputils.HttpClientDetails

func (*CommonConfigFields) GetAccessToken

func (ds *CommonConfigFields) GetAccessToken() string

func (*CommonConfigFields) GetApiKey

func (ds *CommonConfigFields) GetApiKey() string

func (*CommonConfigFields) GetClientCertKeyPath

func (ds *CommonConfigFields) GetClientCertKeyPath() string

func (*CommonConfigFields) GetClientCertPath

func (ds *CommonConfigFields) GetClientCertPath() string

func (*CommonConfigFields) GetPassword

func (ds *CommonConfigFields) GetPassword() string

func (*CommonConfigFields) GetSshAuthHeaders

func (ds *CommonConfigFields) GetSshAuthHeaders() map[string]string

func (*CommonConfigFields) GetSshKeyPath

func (ds *CommonConfigFields) GetSshKeyPath() string

func (*CommonConfigFields) GetSshPassphrase

func (ds *CommonConfigFields) GetSshPassphrase() string

func (*CommonConfigFields) GetSshUrl

func (ds *CommonConfigFields) GetSshUrl() string

func (*CommonConfigFields) GetTokenRefreshHandler

func (ds *CommonConfigFields) GetTokenRefreshHandler() TokenRefreshHandlerFunc

func (*CommonConfigFields) GetUrl

func (ds *CommonConfigFields) GetUrl() string

func (*CommonConfigFields) GetUser

func (ds *CommonConfigFields) GetUser() string

func (*CommonConfigFields) HandleTokenExpiry

func (ds *CommonConfigFields) HandleTokenExpiry(statusCode int, httpClientDetails *httputils.HttpClientDetails) (bool, error)

Checks if a token has expired. If so, acquires a new token from server (if one wasn't acquired yet) and returns true. Otherwise, or in case of an error, returns false.

func (*CommonConfigFields) IsSshAuthHeaderSet

func (ds *CommonConfigFields) IsSshAuthHeaderSet() bool

func (*CommonConfigFields) IsSshAuthentication

func (ds *CommonConfigFields) IsSshAuthentication() bool

func (*CommonConfigFields) SetAccessToken

func (ds *CommonConfigFields) SetAccessToken(accessToken string)

func (*CommonConfigFields) SetApiKey

func (ds *CommonConfigFields) SetApiKey(apiKey string)

func (*CommonConfigFields) SetClientCertKeyPath

func (ds *CommonConfigFields) SetClientCertKeyPath(certificatePath string)

func (*CommonConfigFields) SetClientCertPath

func (ds *CommonConfigFields) SetClientCertPath(certificatePath string)

func (*CommonConfigFields) SetPassword

func (ds *CommonConfigFields) SetPassword(password string)

func (*CommonConfigFields) SetSshAuthHeaders

func (ds *CommonConfigFields) SetSshAuthHeaders(sshAuthHeaders map[string]string)

func (*CommonConfigFields) SetSshKeyPath

func (ds *CommonConfigFields) SetSshKeyPath(sshKeyPath string)

func (*CommonConfigFields) SetSshPassphrase

func (ds *CommonConfigFields) SetSshPassphrase(sshPassphrase string)

func (*CommonConfigFields) SetSshUrl

func (ds *CommonConfigFields) SetSshUrl(sshUrl string)

func (*CommonConfigFields) SetTokenRefreshHandler

func (ds *CommonConfigFields) SetTokenRefreshHandler(tokenRefreshHandler TokenRefreshHandlerFunc)

func (*CommonConfigFields) SetUrl

func (ds *CommonConfigFields) SetUrl(url string)

func (*CommonConfigFields) SetUser

func (ds *CommonConfigFields) SetUser(user string)

type CommonDetails

type CommonDetails interface {
	GetUrl() string
	GetUser() string
	GetPassword() string
	GetApiKey() string
	GetAccessToken() string
	GetTokenRefreshHandler() TokenRefreshHandlerFunc
	GetClientCertPath() string
	GetClientCertKeyPath() string
	GetSshUrl() string
	GetSshKeyPath() string
	GetSshPassphrase() string
	GetSshAuthHeaders() map[string]string
	GetVersion() (string, error)

	SetUrl(url string)
	SetUser(user string)
	SetPassword(password string)
	SetApiKey(apiKey string)
	SetAccessToken(accessToken string)
	SetTokenRefreshHandler(TokenRefreshHandlerFunc)
	SetClientCertPath(certificatePath string)
	SetClientCertKeyPath(certificatePath string)
	SetSshUrl(url string)
	SetSshKeyPath(sshKeyPath string)
	SetSshPassphrase(sshPassphrase string)
	SetSshAuthHeaders(sshAuthHeaders map[string]string)

	IsSshAuthHeaderSet() bool
	IsSshAuthentication() bool
	AuthenticateSsh(sshKey, sshPassphrase string) error
	HandleTokenExpiry(statusCode int, httpClientDetails *httputils.HttpClientDetails) (bool, error)

	CreateHttpClientDetails() httputils.HttpClientDetails
}

type SshAuthResult

type SshAuthResult struct {
	Href    string
	Headers map[string]string
}

type TokenPayload

type TokenPayload struct {
	Subject        string `json:"sub,omitempty"`
	Scope          string `json:"scp,omitempty"`
	Audience       string `json:"aud,omitempty"`
	Issuer         string `json:"iss,omitempty"`
	ExpirationTime int    `json:"exp,omitempty"`
	IssuedAt       int    `json:"iat,omitempty"`
	JwtId          string `json:"jti,omitempty"`
}

type TokenRefreshHandlerFunc

type TokenRefreshHandlerFunc func(currentAccessToken string) (newAccessToken string, err error)

Implement this function and pass it to the CommonDetails struct to handle access token refresh if needed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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