auth

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionDuration = time.Hour * 10
)

Variables

View Source
var ErrInvalidAuth = errors.New("invalid username or password")
View Source
var ErrNoSession = errors.New("no active session")
View Source
var ErrTermsNotAccepted = errors.New("do's and don'ts not accepted, visit: https://naisdevice-approval.external.prod-gcp.nav.cloud.nais.io/ to read and accept")

Functions

func MockDevice

func MockDevice() *pb.Device

func NewSessionStore

func NewSessionStore(db database.Database) *sessionStore

Types

type Authenticator

type Authenticator interface {
	Login(ctx context.Context, token, serial, platform string) (*pb.Session, error)
}

func NewAuthenticator

func NewAuthenticator(azureConfig *auth.Azure, db database.Database, store SessionStore, log logrus.FieldLogger) Authenticator

func NewGoogleAuthenticator

func NewGoogleAuthenticator(googleConfig *auth.Google, db database.Database, store SessionStore) Authenticator

func NewMockAuthenticator

func NewMockAuthenticator(store SessionStore) Authenticator

type LegacySessionInfo

type LegacySessionInfo struct {
	Key    string `json:"key"`
	Expiry int64  `json:"expiry"`
}

func LegacySessionFromProtobuf

func LegacySessionFromProtobuf(s *pb.Session) *LegacySessionInfo

func (*LegacySessionInfo) ToProtobuf

func (s *LegacySessionInfo) ToProtobuf() *pb.Session

type MockSessionStore

type MockSessionStore struct {
	mock.Mock
}

MockSessionStore is an autogenerated mock type for the SessionStore type

func NewMockSessionStore

func NewMockSessionStore(t interface {
	mock.TestingT
	Cleanup(func())
},
) *MockSessionStore

NewMockSessionStore creates a new instance of MockSessionStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockSessionStore) All

func (_mock *MockSessionStore) All() []*pb.Session

All provides a mock function for the type MockSessionStore

func (*MockSessionStore) EXPECT

func (*MockSessionStore) Get

func (_mock *MockSessionStore) Get(context1 context.Context, s string) (*pb.Session, error)

Get provides a mock function for the type MockSessionStore

func (*MockSessionStore) RefreshDevice

func (_mock *MockSessionStore) RefreshDevice(device *pb.Device)

RefreshDevice provides a mock function for the type MockSessionStore

func (*MockSessionStore) Set

func (_mock *MockSessionStore) Set(context1 context.Context, session *pb.Session) error

Set provides a mock function for the type MockSessionStore

type MockSessionStore_All_Call

type MockSessionStore_All_Call struct {
	*mock.Call
}

MockSessionStore_All_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'All'

func (*MockSessionStore_All_Call) Return

func (*MockSessionStore_All_Call) Run

func (*MockSessionStore_All_Call) RunAndReturn

func (_c *MockSessionStore_All_Call) RunAndReturn(run func() []*pb.Session) *MockSessionStore_All_Call

type MockSessionStore_Expecter

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

func (*MockSessionStore_Expecter) All

All is a helper method to define mock.On call

func (*MockSessionStore_Expecter) Get

func (_e *MockSessionStore_Expecter) Get(context1 interface{}, s interface{}) *MockSessionStore_Get_Call

Get is a helper method to define mock.On call

  • context1 context.Context
  • s string

func (*MockSessionStore_Expecter) RefreshDevice

func (_e *MockSessionStore_Expecter) RefreshDevice(device interface{}) *MockSessionStore_RefreshDevice_Call

RefreshDevice is a helper method to define mock.On call

  • device *pb.Device

func (*MockSessionStore_Expecter) Set

func (_e *MockSessionStore_Expecter) Set(context1 interface{}, session interface{}) *MockSessionStore_Set_Call

Set is a helper method to define mock.On call

  • context1 context.Context
  • session *pb.Session

type MockSessionStore_Get_Call

type MockSessionStore_Get_Call struct {
	*mock.Call
}

MockSessionStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'

func (*MockSessionStore_Get_Call) Return

func (*MockSessionStore_Get_Call) Run

func (*MockSessionStore_Get_Call) RunAndReturn

func (_c *MockSessionStore_Get_Call) RunAndReturn(run func(context1 context.Context, s string) (*pb.Session, error)) *MockSessionStore_Get_Call

type MockSessionStore_RefreshDevice_Call

type MockSessionStore_RefreshDevice_Call struct {
	*mock.Call
}

MockSessionStore_RefreshDevice_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RefreshDevice'

func (*MockSessionStore_RefreshDevice_Call) Return

func (*MockSessionStore_RefreshDevice_Call) Run

func (*MockSessionStore_RefreshDevice_Call) RunAndReturn

type MockSessionStore_Set_Call

type MockSessionStore_Set_Call struct {
	*mock.Call
}

MockSessionStore_Set_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Set'

func (*MockSessionStore_Set_Call) Return

func (*MockSessionStore_Set_Call) Run

func (_c *MockSessionStore_Set_Call) Run(run func(context1 context.Context, session *pb.Session)) *MockSessionStore_Set_Call

func (*MockSessionStore_Set_Call) RunAndReturn

func (_c *MockSessionStore_Set_Call) RunAndReturn(run func(context1 context.Context, session *pb.Session) error) *MockSessionStore_Set_Call

type ParseTokenError

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

JWT token parsing errors. The token library does not have any standardised error types, so we need one here to accurately represent this type of error.

func (ParseTokenError) Error

func (t ParseTokenError) Error() string

type SessionStore

type SessionStore interface {
	Get(context.Context, string) (*pb.Session, error)
	Set(context.Context, *pb.Session) error
	All() []*pb.Session
	RefreshDevice(*pb.Device)
}

type UsernamePasswordAuthenticator

type UsernamePasswordAuthenticator interface {
	Authenticate(ctx context.Context, username, password string) error
}

func NewAPIKeyAuthenticator

func NewAPIKeyAuthenticator(users map[string]string) UsernamePasswordAuthenticator

func NewMockAPIKeyAuthenticator

func NewMockAPIKeyAuthenticator() UsernamePasswordAuthenticator

Jump to

Keyboard shortcuts

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