authentication

package
v0.0.0-...-b692957 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const ExpirationMsg = "Your authentication failed due to token expiration. Please re-authenticate to continue using Snyk."
View Source
const InvalidCredsMessage = "" /* 129-byte string literal not displayed */

Variables

View Source
var ErrEmptyAPIToken = errors.New("auth-provider: api token is not set")

Functions

func AuthenticationCheck

func AuthenticationCheck() (string, error)

Types

type ActiveUser

type ActiveUser struct {
	Id       string `json:"id"`
	UserName string `json:"username,omitempty"`
	Orgs     []struct {
		Name  string `json:"name,omitempty"`
		Id    string `json:"id,omitempty"`
		Group struct {
			Name string `json:"name,omitempty"`
			Id   string `json:"id,omitempty"`
		} `json:"group,omitempty"`
	} `json:"orgs,omitempty"`
}

func GetActiveUser

func GetActiveUser() (*ActiveUser, error)

type AuthenticationFailedError

type AuthenticationFailedError struct {
	ManualAuthentication bool
}

func (*AuthenticationFailedError) Error

func (e *AuthenticationFailedError) Error() string

type AuthenticationFunction

type AuthenticationFunction func() (string, error)

type AuthenticationProvider

type AuthenticationProvider interface {
	// Authenticate triggers the authentication. This may involve manual steps, like logging in using a browser
	Authenticate(ctx context.Context) (string, error)

	// ClearAuthentication removes all authentication information from the configuration
	ClearAuthentication(ctx context.Context) error

	// AuthURL returns the latest provided AuthenticationURL. This can be empty.
	AuthURL(ctx context.Context) string

	GetCheckAuthenticationFunction() AuthenticationFunction
	// contains filtered or unexported methods
}

func Default

func Default(c *config.Config, authenticationService AuthenticationService) AuthenticationProvider

Default authentication configures an OAuth2 authenticator, the auth service parameter is needed, as the oauth2 provider needs a callback function

func Token

Token authentication configures token only authentication

type AuthenticationService

type AuthenticationService interface {
	// Authenticate attempts to authenticate the user, and sends a notification to the client when successful
	Authenticate(ctx context.Context) (string, error)

	// Provider returns current authentication provider.
	Provider() AuthenticationProvider

	// UpdateCredentials stores the token in the configuration, and sends a $/snyk.hasAuthenticated notification to the
	// client if sendNotification is true
	UpdateCredentials(newToken string, sendNotification bool, updateApiUrl bool)

	Logout(ctx context.Context)

	// IsAuthenticated returns true if the token is verified
	IsAuthenticated() bool

	// SetProvider sets the authentication provider
	SetProvider(provider AuthenticationProvider)

	// ConfigureProviders updates the providers based on the stored configuration
	ConfigureProviders(c *config.Config)
	// contains filtered or unexported methods
}

func NewAuthenticationService

func NewAuthenticationService(c *config.Config, authProviders AuthenticationProvider, errorReporter error_reporting.ErrorReporter, notifier noti.Notifier) AuthenticationService

type AuthenticationServiceImpl

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

func (*AuthenticationServiceImpl) Authenticate

func (a *AuthenticationServiceImpl) Authenticate(ctx context.Context) (token string, err error)

func (*AuthenticationServiceImpl) ConfigureProviders

func (a *AuthenticationServiceImpl) ConfigureProviders(c *config.Config)

func (*AuthenticationServiceImpl) IsAuthenticated

func (a *AuthenticationServiceImpl) IsAuthenticated() bool

IsAuthenticated returns true if the token is verified If the token is set, but not valid IsAuthenticated returns false

func (*AuthenticationServiceImpl) Logout

func (a *AuthenticationServiceImpl) Logout(ctx context.Context)

func (*AuthenticationServiceImpl) Provider

func (*AuthenticationServiceImpl) SetProvider

func (a *AuthenticationServiceImpl) SetProvider(provider AuthenticationProvider)

func (*AuthenticationServiceImpl) UpdateCredentials

func (a *AuthenticationServiceImpl) UpdateCredentials(newToken string, sendNotification bool, updateApiUrl bool)

type CliAuthenticationProvider

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

func NewCliAuthenticationProvider

func NewCliAuthenticationProvider(c *config.Config, errorReporter error_reporting.ErrorReporter) *CliAuthenticationProvider

func (*CliAuthenticationProvider) AuthURL

func (*CliAuthenticationProvider) Authenticate

func (a *CliAuthenticationProvider) Authenticate(ctx context.Context) (string, error)

func (*CliAuthenticationProvider) ClearAuthentication

func (a *CliAuthenticationProvider) ClearAuthentication(ctx context.Context) error

func (*CliAuthenticationProvider) GetCheckAuthenticationFunction

func (a *CliAuthenticationProvider) GetCheckAuthenticationFunction() AuthenticationFunction

type FakeAuthenticationProvider

type FakeAuthenticationProvider struct {
	ExpectedAuthURL string
	IsAuthenticated bool

	C *config.Config
	// contains filtered or unexported fields
}

func NewFakeCliAuthenticationProvider

func NewFakeCliAuthenticationProvider(c *config.Config) *FakeAuthenticationProvider

func (*FakeAuthenticationProvider) AuthURL

func (*FakeAuthenticationProvider) Authenticate

func (a *FakeAuthenticationProvider) Authenticate(_ context.Context) (string, error)

func (*FakeAuthenticationProvider) ClearAuthentication

func (a *FakeAuthenticationProvider) ClearAuthentication(_ context.Context) error

func (*FakeAuthenticationProvider) GetCheckAuthenticationFunction

func (a *FakeAuthenticationProvider) GetCheckAuthenticationFunction() AuthenticationFunction

type Initializer

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

func NewInitializer

func NewInitializer(c *config.Config, authenticator AuthenticationService, errorReporter error_reporting.ErrorReporter, notifier noti.Notifier) *Initializer

func (*Initializer) Init

func (i *Initializer) Init() error

type OAuth2Provider

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

func NewOAuthProvider

func NewOAuthProvider(
	c *config.Config,
	customTokenRefresherFunc func(ctx context.Context, oauthConfig *oauth2.Config, token *oauth2.Token) (*oauth2.Token, error),
	credentialsUpdateCallback storage.StorageCallbackFunc,
	openBrowserFunc func(string),
) *OAuth2Provider

func (*OAuth2Provider) AuthURL

func (p *OAuth2Provider) AuthURL(_ context.Context) string

func (*OAuth2Provider) Authenticate

func (p *OAuth2Provider) Authenticate(_ context.Context) (string, error)

func (*OAuth2Provider) Authenticator

func (p *OAuth2Provider) Authenticator() auth.Authenticator

func (*OAuth2Provider) ClearAuthentication

func (p *OAuth2Provider) ClearAuthentication(_ context.Context) error

func (*OAuth2Provider) GetCheckAuthenticationFunction

func (p *OAuth2Provider) GetCheckAuthenticationFunction() AuthenticationFunction

Jump to

Keyboard shortcuts

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