Documentation
¶
Index ¶
- Variables
- func JSONResponse(w http.ResponseWriter, data interface{}, status int)
- func RedirectUnauthorized(target url.URL) http.HandlerFunc
- func Unauthorized(w http.ResponseWriter, _ *http.Request)
- func UserIDFromCtx(ctx context.Context, pkUserKey AuthUserIDKey) ([]byte, bool)
- type AuthUserIDKey
- type Config
- type CookieSettings
- type Logger
- type MockLogger
- type MockLogger_Debugf_Call
- type MockLogger_Errorf_Call
- type MockLogger_Expecter
- func (_e *MockLogger_Expecter) Debugf(format interface{}, v ...interface{}) *MockLogger_Debugf_Call
- func (_e *MockLogger_Expecter) Errorf(format interface{}, v ...interface{}) *MockLogger_Errorf_Call
- func (_e *MockLogger_Expecter) Infof(format interface{}, v ...interface{}) *MockLogger_Infof_Call
- func (_e *MockLogger_Expecter) Warnf(format interface{}, v ...interface{}) *MockLogger_Warnf_Call
- type MockLogger_Infof_Call
- type MockLogger_Warnf_Call
- type MockSessionStore
- func (_m *MockSessionStore[T]) Consume(token string) (*T, bool)
- func (_m *MockSessionStore[T]) Create(data T) (string, error)
- func (_m *MockSessionStore[T]) Delete(token string)
- func (_m *MockSessionStore[T]) EXPECT() *MockSessionStore_Expecter[T]
- func (_m *MockSessionStore[T]) Get(token string) (*T, bool)
- type MockSessionStore_Consume_Call
- func (_c *MockSessionStore_Consume_Call[T]) Return(_a0 *T, _a1 bool) *MockSessionStore_Consume_Call[T]
- func (_c *MockSessionStore_Consume_Call[T]) Run(run func(token string)) *MockSessionStore_Consume_Call[T]
- func (_c *MockSessionStore_Consume_Call[T]) RunAndReturn(run func(string) (*T, bool)) *MockSessionStore_Consume_Call[T]
- type MockSessionStore_Create_Call
- func (_c *MockSessionStore_Create_Call[T]) Return(_a0 string, _a1 error) *MockSessionStore_Create_Call[T]
- func (_c *MockSessionStore_Create_Call[T]) Run(run func(data T)) *MockSessionStore_Create_Call[T]
- func (_c *MockSessionStore_Create_Call[T]) RunAndReturn(run func(T) (string, error)) *MockSessionStore_Create_Call[T]
- type MockSessionStore_Delete_Call
- type MockSessionStore_Expecter
- func (_e *MockSessionStore_Expecter[T]) Consume(token interface{}) *MockSessionStore_Consume_Call[T]
- func (_e *MockSessionStore_Expecter[T]) Create(data interface{}) *MockSessionStore_Create_Call[T]
- func (_e *MockSessionStore_Expecter[T]) Delete(token interface{}) *MockSessionStore_Delete_Call[T]
- func (_e *MockSessionStore_Expecter[T]) Get(token interface{}) *MockSessionStore_Get_Call[T]
- type MockSessionStore_Get_Call
- func (_c *MockSessionStore_Get_Call[T]) Return(_a0 *T, _a1 bool) *MockSessionStore_Get_Call[T]
- func (_c *MockSessionStore_Get_Call[T]) Run(run func(token string)) *MockSessionStore_Get_Call[T]
- func (_c *MockSessionStore_Get_Call[T]) RunAndReturn(run func(string) (*T, bool)) *MockSessionStore_Get_Call[T]
- type MockUser
- type MockUserStore
- func (_mock *MockUserStore) Create(u NewUser) (User, error)
- func (_m *MockUserStore) EXPECT() *MockUserStore_Expecter
- func (_mock *MockUserStore) Get(userID []byte) (User, error)
- func (_mock *MockUserStore) GetByName(username string) (User, error)
- func (_mock *MockUserStore) UpdateCredential(userID []byte, credential webauthn.Credential) error
- type MockUserStore_Create_Call
- type MockUserStore_Expecter
- func (_e *MockUserStore_Expecter) Create(u any) *MockUserStore_Create_Call
- func (_e *MockUserStore_Expecter) Get(userID any) *MockUserStore_Get_Call
- func (_e *MockUserStore_Expecter) GetByName(username any) *MockUserStore_GetByName_Call
- func (_e *MockUserStore_Expecter) UpdateCredential(userID any, credential any) *MockUserStore_UpdateCredential_Call
- type MockUserStore_GetByName_Call
- func (_c *MockUserStore_GetByName_Call) Return(user User, err error) *MockUserStore_GetByName_Call
- func (_c *MockUserStore_GetByName_Call) Run(run func(username string)) *MockUserStore_GetByName_Call
- func (_c *MockUserStore_GetByName_Call) RunAndReturn(run func(username string) (User, error)) *MockUserStore_GetByName_Call
- type MockUserStore_Get_Call
- type MockUserStore_UpdateCredential_Call
- func (_c *MockUserStore_UpdateCredential_Call) Return(err error) *MockUserStore_UpdateCredential_Call
- func (_c *MockUserStore_UpdateCredential_Call) Run(run func(userID []byte, credential webauthn.Credential)) *MockUserStore_UpdateCredential_Call
- func (_c *MockUserStore_UpdateCredential_Call) RunAndReturn(run func(userID []byte, credential webauthn.Credential) error) *MockUserStore_UpdateCredential_Call
- type MockUser_Expecter
- func (_e *MockUser_Expecter) WebAuthnCredentials() *MockUser_WebAuthnCredentials_Call
- func (_e *MockUser_Expecter) WebAuthnDisplayName() *MockUser_WebAuthnDisplayName_Call
- func (_e *MockUser_Expecter) WebAuthnID() *MockUser_WebAuthnID_Call
- func (_e *MockUser_Expecter) WebAuthnName() *MockUser_WebAuthnName_Call
- type MockUser_WebAuthnCredentials_Call
- func (_c *MockUser_WebAuthnCredentials_Call) Return(credentials []webauthn.Credential) *MockUser_WebAuthnCredentials_Call
- func (_c *MockUser_WebAuthnCredentials_Call) Run(run func()) *MockUser_WebAuthnCredentials_Call
- func (_c *MockUser_WebAuthnCredentials_Call) RunAndReturn(run func() []webauthn.Credential) *MockUser_WebAuthnCredentials_Call
- type MockUser_WebAuthnDisplayName_Call
- func (_c *MockUser_WebAuthnDisplayName_Call) Return(s string) *MockUser_WebAuthnDisplayName_Call
- func (_c *MockUser_WebAuthnDisplayName_Call) Run(run func()) *MockUser_WebAuthnDisplayName_Call
- func (_c *MockUser_WebAuthnDisplayName_Call) RunAndReturn(run func() string) *MockUser_WebAuthnDisplayName_Call
- type MockUser_WebAuthnID_Call
- type MockUser_WebAuthnName_Call
- type NewUser
- type Option
- type Passkey
- type RegistrationSessionData
- type SessionStore
- type User
- type UserSessionData
- type UserStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoUsername = fmt.Errorf("no username provided") ErrUsernameTooLong = fmt.Errorf("username exceeds 256 bytes") ErrUserNotFound = fmt.Errorf("user not found") ErrCredentialNotFound = fmt.Errorf("credential not found") ErrUserAlreadyExists = fmt.Errorf("user already exists") ErrSessionStoreFull = fmt.Errorf("session storage is full") )
Functions ¶
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, data interface{}, status int)
JSONResponse sends json response
func RedirectUnauthorized ¶
func RedirectUnauthorized(target url.URL) http.HandlerFunc
RedirectUnauthorized returns a 303 redirect to a local target, or Unauthorized for an invalid target.
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, _ *http.Request)
Unauthorized writes a 401 Unauthorized status code to the response.
func UserIDFromCtx ¶
func UserIDFromCtx(ctx context.Context, pkUserKey AuthUserIDKey) ([]byte, bool)
UserIDFromCtx returns the user ID from the request context. If the userID is not found, it returns nil and false.
Types ¶
type AuthUserIDKey ¶
type AuthUserIDKey string
type Config ¶
type Config struct {
WebauthnConfig *webauthn.Config
UserStore
LoginSessionStore SessionStore[webauthn.SessionData]
RegistrationSessionStore SessionStore[RegistrationSessionData]
UserSessionStore SessionStore[UserSessionData]
}
type CookieSettings ¶
type Logger ¶
type Logger interface {
Errorf(format string, v ...any)
Debugf(format string, v ...any)
Infof(format string, v ...any)
Warnf(format string, v ...any)
}
Logger is a simple logger interface
type MockLogger ¶
MockLogger is an autogenerated mock type for the Logger type
func NewMockLogger ¶
func NewMockLogger(t interface {
mock.TestingT
Cleanup(func())
}) *MockLogger
NewMockLogger creates a new instance of MockLogger. 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 (*MockLogger) Debugf ¶
func (_m *MockLogger) Debugf(format string, v ...any)
Debugf provides a mock function with given fields: format, v
func (*MockLogger) EXPECT ¶
func (_m *MockLogger) EXPECT() *MockLogger_Expecter
func (*MockLogger) Errorf ¶
func (_m *MockLogger) Errorf(format string, v ...any)
Errorf provides a mock function with given fields: format, v
func (*MockLogger) Infof ¶
func (_m *MockLogger) Infof(format string, v ...any)
Infof provides a mock function with given fields: format, v
func (*MockLogger) Warnf ¶
func (_m *MockLogger) Warnf(format string, v ...any)
Warnf provides a mock function with given fields: format, v
type MockLogger_Debugf_Call ¶
MockLogger_Debugf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Debugf'
func (*MockLogger_Debugf_Call) Return ¶
func (_c *MockLogger_Debugf_Call) Return() *MockLogger_Debugf_Call
func (*MockLogger_Debugf_Call) Run ¶
func (_c *MockLogger_Debugf_Call) Run(run func(format string, v ...any)) *MockLogger_Debugf_Call
func (*MockLogger_Debugf_Call) RunAndReturn ¶
func (_c *MockLogger_Debugf_Call) RunAndReturn(run func(string, ...any)) *MockLogger_Debugf_Call
type MockLogger_Errorf_Call ¶
MockLogger_Errorf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Errorf'
func (*MockLogger_Errorf_Call) Return ¶
func (_c *MockLogger_Errorf_Call) Return() *MockLogger_Errorf_Call
func (*MockLogger_Errorf_Call) Run ¶
func (_c *MockLogger_Errorf_Call) Run(run func(format string, v ...any)) *MockLogger_Errorf_Call
func (*MockLogger_Errorf_Call) RunAndReturn ¶
func (_c *MockLogger_Errorf_Call) RunAndReturn(run func(string, ...any)) *MockLogger_Errorf_Call
type MockLogger_Expecter ¶
type MockLogger_Expecter struct {
// contains filtered or unexported fields
}
func (*MockLogger_Expecter) Debugf ¶
func (_e *MockLogger_Expecter) Debugf(format interface{}, v ...interface{}) *MockLogger_Debugf_Call
Debugf is a helper method to define mock.On call
- format string
- v ...any
func (*MockLogger_Expecter) Errorf ¶
func (_e *MockLogger_Expecter) Errorf(format interface{}, v ...interface{}) *MockLogger_Errorf_Call
Errorf is a helper method to define mock.On call
- format string
- v ...any
func (*MockLogger_Expecter) Infof ¶
func (_e *MockLogger_Expecter) Infof(format interface{}, v ...interface{}) *MockLogger_Infof_Call
Infof is a helper method to define mock.On call
- format string
- v ...any
func (*MockLogger_Expecter) Warnf ¶
func (_e *MockLogger_Expecter) Warnf(format interface{}, v ...interface{}) *MockLogger_Warnf_Call
Warnf is a helper method to define mock.On call
- format string
- v ...any
type MockLogger_Infof_Call ¶
MockLogger_Infof_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Infof'
func (*MockLogger_Infof_Call) Return ¶
func (_c *MockLogger_Infof_Call) Return() *MockLogger_Infof_Call
func (*MockLogger_Infof_Call) Run ¶
func (_c *MockLogger_Infof_Call) Run(run func(format string, v ...any)) *MockLogger_Infof_Call
func (*MockLogger_Infof_Call) RunAndReturn ¶
func (_c *MockLogger_Infof_Call) RunAndReturn(run func(string, ...any)) *MockLogger_Infof_Call
type MockLogger_Warnf_Call ¶
MockLogger_Warnf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Warnf'
func (*MockLogger_Warnf_Call) Return ¶
func (_c *MockLogger_Warnf_Call) Return() *MockLogger_Warnf_Call
func (*MockLogger_Warnf_Call) Run ¶
func (_c *MockLogger_Warnf_Call) Run(run func(format string, v ...any)) *MockLogger_Warnf_Call
func (*MockLogger_Warnf_Call) RunAndReturn ¶
func (_c *MockLogger_Warnf_Call) RunAndReturn(run func(string, ...any)) *MockLogger_Warnf_Call
type MockSessionStore ¶
MockSessionStore is an autogenerated mock type for the SessionStore type
func NewMockSessionStore ¶
func NewMockSessionStore[T any](t interface { mock.TestingT Cleanup(func()) }) *MockSessionStore[T]
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[T]) Consume ¶
func (_m *MockSessionStore[T]) Consume(token string) (*T, bool)
Consume provides a mock function with given fields: token
func (*MockSessionStore[T]) Create ¶
func (_m *MockSessionStore[T]) Create(data T) (string, error)
Create provides a mock function with given fields: data
func (*MockSessionStore[T]) Delete ¶
func (_m *MockSessionStore[T]) Delete(token string)
Delete provides a mock function with given fields: token
func (*MockSessionStore[T]) EXPECT ¶
func (_m *MockSessionStore[T]) EXPECT() *MockSessionStore_Expecter[T]
func (*MockSessionStore[T]) Get ¶
func (_m *MockSessionStore[T]) Get(token string) (*T, bool)
Get provides a mock function with given fields: token
type MockSessionStore_Consume_Call ¶
MockSessionStore_Consume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Consume'
func (*MockSessionStore_Consume_Call[T]) Return ¶
func (_c *MockSessionStore_Consume_Call[T]) Return(_a0 *T, _a1 bool) *MockSessionStore_Consume_Call[T]
func (*MockSessionStore_Consume_Call[T]) Run ¶
func (_c *MockSessionStore_Consume_Call[T]) Run(run func(token string)) *MockSessionStore_Consume_Call[T]
func (*MockSessionStore_Consume_Call[T]) RunAndReturn ¶
func (_c *MockSessionStore_Consume_Call[T]) RunAndReturn(run func(string) (*T, bool)) *MockSessionStore_Consume_Call[T]
type MockSessionStore_Create_Call ¶
MockSessionStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create'
func (*MockSessionStore_Create_Call[T]) Return ¶
func (_c *MockSessionStore_Create_Call[T]) Return(_a0 string, _a1 error) *MockSessionStore_Create_Call[T]
func (*MockSessionStore_Create_Call[T]) Run ¶
func (_c *MockSessionStore_Create_Call[T]) Run(run func(data T)) *MockSessionStore_Create_Call[T]
func (*MockSessionStore_Create_Call[T]) RunAndReturn ¶
func (_c *MockSessionStore_Create_Call[T]) RunAndReturn(run func(T) (string, error)) *MockSessionStore_Create_Call[T]
type MockSessionStore_Delete_Call ¶
MockSessionStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete'
func (*MockSessionStore_Delete_Call[T]) Return ¶
func (_c *MockSessionStore_Delete_Call[T]) Return() *MockSessionStore_Delete_Call[T]
func (*MockSessionStore_Delete_Call[T]) Run ¶
func (_c *MockSessionStore_Delete_Call[T]) Run(run func(token string)) *MockSessionStore_Delete_Call[T]
func (*MockSessionStore_Delete_Call[T]) RunAndReturn ¶
func (_c *MockSessionStore_Delete_Call[T]) RunAndReturn(run func(string)) *MockSessionStore_Delete_Call[T]
type MockSessionStore_Expecter ¶
type MockSessionStore_Expecter[T any] struct { // contains filtered or unexported fields }
func (*MockSessionStore_Expecter[T]) Consume ¶
func (_e *MockSessionStore_Expecter[T]) Consume(token interface{}) *MockSessionStore_Consume_Call[T]
Consume is a helper method to define mock.On call
- token string
func (*MockSessionStore_Expecter[T]) Create ¶
func (_e *MockSessionStore_Expecter[T]) Create(data interface{}) *MockSessionStore_Create_Call[T]
Create is a helper method to define mock.On call
- data T
func (*MockSessionStore_Expecter[T]) Delete ¶
func (_e *MockSessionStore_Expecter[T]) Delete(token interface{}) *MockSessionStore_Delete_Call[T]
Delete is a helper method to define mock.On call
- token string
func (*MockSessionStore_Expecter[T]) Get ¶
func (_e *MockSessionStore_Expecter[T]) Get(token interface{}) *MockSessionStore_Get_Call[T]
Get is a helper method to define mock.On call
- token string
type MockSessionStore_Get_Call ¶
MockSessionStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'
func (*MockSessionStore_Get_Call[T]) Return ¶
func (_c *MockSessionStore_Get_Call[T]) Return(_a0 *T, _a1 bool) *MockSessionStore_Get_Call[T]
func (*MockSessionStore_Get_Call[T]) Run ¶
func (_c *MockSessionStore_Get_Call[T]) Run(run func(token string)) *MockSessionStore_Get_Call[T]
func (*MockSessionStore_Get_Call[T]) RunAndReturn ¶
func (_c *MockSessionStore_Get_Call[T]) RunAndReturn(run func(string) (*T, bool)) *MockSessionStore_Get_Call[T]
type MockUser ¶
MockUser is an autogenerated mock type for the User type
func NewMockUser ¶
NewMockUser creates a new instance of MockUser. 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 (*MockUser) EXPECT ¶
func (_m *MockUser) EXPECT() *MockUser_Expecter
func (*MockUser) WebAuthnCredentials ¶
func (_mock *MockUser) WebAuthnCredentials() []webauthn.Credential
WebAuthnCredentials provides a mock function for the type MockUser
func (*MockUser) WebAuthnDisplayName ¶
WebAuthnDisplayName provides a mock function for the type MockUser
func (*MockUser) WebAuthnID ¶
WebAuthnID provides a mock function for the type MockUser
func (*MockUser) WebAuthnName ¶
WebAuthnName provides a mock function for the type MockUser
type MockUserStore ¶
MockUserStore is an autogenerated mock type for the UserStore type
func NewMockUserStore ¶
func NewMockUserStore(t interface {
mock.TestingT
Cleanup(func())
}) *MockUserStore
NewMockUserStore creates a new instance of MockUserStore. 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 (*MockUserStore) Create ¶
func (_mock *MockUserStore) Create(u NewUser) (User, error)
Create provides a mock function for the type MockUserStore
func (*MockUserStore) EXPECT ¶
func (_m *MockUserStore) EXPECT() *MockUserStore_Expecter
func (*MockUserStore) Get ¶
func (_mock *MockUserStore) Get(userID []byte) (User, error)
Get provides a mock function for the type MockUserStore
func (*MockUserStore) GetByName ¶
func (_mock *MockUserStore) GetByName(username string) (User, error)
GetByName provides a mock function for the type MockUserStore
func (*MockUserStore) UpdateCredential ¶
func (_mock *MockUserStore) UpdateCredential(userID []byte, credential webauthn.Credential) error
UpdateCredential provides a mock function for the type MockUserStore
type MockUserStore_Create_Call ¶
MockUserStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create'
func (*MockUserStore_Create_Call) Return ¶
func (_c *MockUserStore_Create_Call) Return(user User, err error) *MockUserStore_Create_Call
func (*MockUserStore_Create_Call) Run ¶
func (_c *MockUserStore_Create_Call) Run(run func(u NewUser)) *MockUserStore_Create_Call
func (*MockUserStore_Create_Call) RunAndReturn ¶
func (_c *MockUserStore_Create_Call) RunAndReturn(run func(u NewUser) (User, error)) *MockUserStore_Create_Call
type MockUserStore_Expecter ¶
type MockUserStore_Expecter struct {
// contains filtered or unexported fields
}
func (*MockUserStore_Expecter) Create ¶
func (_e *MockUserStore_Expecter) Create(u any) *MockUserStore_Create_Call
Create is a helper method to define mock.On call
- u NewUser
func (*MockUserStore_Expecter) Get ¶
func (_e *MockUserStore_Expecter) Get(userID any) *MockUserStore_Get_Call
Get is a helper method to define mock.On call
- userID []byte
func (*MockUserStore_Expecter) GetByName ¶
func (_e *MockUserStore_Expecter) GetByName(username any) *MockUserStore_GetByName_Call
GetByName is a helper method to define mock.On call
- username string
func (*MockUserStore_Expecter) UpdateCredential ¶
func (_e *MockUserStore_Expecter) UpdateCredential(userID any, credential any) *MockUserStore_UpdateCredential_Call
UpdateCredential is a helper method to define mock.On call
- userID []byte
- credential webauthn.Credential
type MockUserStore_GetByName_Call ¶
MockUserStore_GetByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByName'
func (*MockUserStore_GetByName_Call) Return ¶
func (_c *MockUserStore_GetByName_Call) Return(user User, err error) *MockUserStore_GetByName_Call
func (*MockUserStore_GetByName_Call) Run ¶
func (_c *MockUserStore_GetByName_Call) Run(run func(username string)) *MockUserStore_GetByName_Call
func (*MockUserStore_GetByName_Call) RunAndReturn ¶
func (_c *MockUserStore_GetByName_Call) RunAndReturn(run func(username string) (User, error)) *MockUserStore_GetByName_Call
type MockUserStore_Get_Call ¶
MockUserStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'
func (*MockUserStore_Get_Call) Return ¶
func (_c *MockUserStore_Get_Call) Return(user User, err error) *MockUserStore_Get_Call
func (*MockUserStore_Get_Call) Run ¶
func (_c *MockUserStore_Get_Call) Run(run func(userID []byte)) *MockUserStore_Get_Call
func (*MockUserStore_Get_Call) RunAndReturn ¶
func (_c *MockUserStore_Get_Call) RunAndReturn(run func(userID []byte) (User, error)) *MockUserStore_Get_Call
type MockUserStore_UpdateCredential_Call ¶
MockUserStore_UpdateCredential_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCredential'
func (*MockUserStore_UpdateCredential_Call) Return ¶
func (_c *MockUserStore_UpdateCredential_Call) Return(err error) *MockUserStore_UpdateCredential_Call
func (*MockUserStore_UpdateCredential_Call) Run ¶
func (_c *MockUserStore_UpdateCredential_Call) Run(run func(userID []byte, credential webauthn.Credential)) *MockUserStore_UpdateCredential_Call
func (*MockUserStore_UpdateCredential_Call) RunAndReturn ¶
func (_c *MockUserStore_UpdateCredential_Call) RunAndReturn(run func(userID []byte, credential webauthn.Credential) error) *MockUserStore_UpdateCredential_Call
type MockUser_Expecter ¶
type MockUser_Expecter struct {
// contains filtered or unexported fields
}
func (*MockUser_Expecter) WebAuthnCredentials ¶
func (_e *MockUser_Expecter) WebAuthnCredentials() *MockUser_WebAuthnCredentials_Call
WebAuthnCredentials is a helper method to define mock.On call
func (*MockUser_Expecter) WebAuthnDisplayName ¶
func (_e *MockUser_Expecter) WebAuthnDisplayName() *MockUser_WebAuthnDisplayName_Call
WebAuthnDisplayName is a helper method to define mock.On call
func (*MockUser_Expecter) WebAuthnID ¶
func (_e *MockUser_Expecter) WebAuthnID() *MockUser_WebAuthnID_Call
WebAuthnID is a helper method to define mock.On call
func (*MockUser_Expecter) WebAuthnName ¶
func (_e *MockUser_Expecter) WebAuthnName() *MockUser_WebAuthnName_Call
WebAuthnName is a helper method to define mock.On call
type MockUser_WebAuthnCredentials_Call ¶
MockUser_WebAuthnCredentials_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WebAuthnCredentials'
func (*MockUser_WebAuthnCredentials_Call) Return ¶
func (_c *MockUser_WebAuthnCredentials_Call) Return(credentials []webauthn.Credential) *MockUser_WebAuthnCredentials_Call
func (*MockUser_WebAuthnCredentials_Call) Run ¶
func (_c *MockUser_WebAuthnCredentials_Call) Run(run func()) *MockUser_WebAuthnCredentials_Call
func (*MockUser_WebAuthnCredentials_Call) RunAndReturn ¶
func (_c *MockUser_WebAuthnCredentials_Call) RunAndReturn(run func() []webauthn.Credential) *MockUser_WebAuthnCredentials_Call
type MockUser_WebAuthnDisplayName_Call ¶
MockUser_WebAuthnDisplayName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WebAuthnDisplayName'
func (*MockUser_WebAuthnDisplayName_Call) Return ¶
func (_c *MockUser_WebAuthnDisplayName_Call) Return(s string) *MockUser_WebAuthnDisplayName_Call
func (*MockUser_WebAuthnDisplayName_Call) Run ¶
func (_c *MockUser_WebAuthnDisplayName_Call) Run(run func()) *MockUser_WebAuthnDisplayName_Call
func (*MockUser_WebAuthnDisplayName_Call) RunAndReturn ¶
func (_c *MockUser_WebAuthnDisplayName_Call) RunAndReturn(run func() string) *MockUser_WebAuthnDisplayName_Call
type MockUser_WebAuthnID_Call ¶
MockUser_WebAuthnID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WebAuthnID'
func (*MockUser_WebAuthnID_Call) Return ¶
func (_c *MockUser_WebAuthnID_Call) Return(bytes []byte) *MockUser_WebAuthnID_Call
func (*MockUser_WebAuthnID_Call) Run ¶
func (_c *MockUser_WebAuthnID_Call) Run(run func()) *MockUser_WebAuthnID_Call
func (*MockUser_WebAuthnID_Call) RunAndReturn ¶
func (_c *MockUser_WebAuthnID_Call) RunAndReturn(run func() []byte) *MockUser_WebAuthnID_Call
type MockUser_WebAuthnName_Call ¶
MockUser_WebAuthnName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WebAuthnName'
func (*MockUser_WebAuthnName_Call) Return ¶
func (_c *MockUser_WebAuthnName_Call) Return(s string) *MockUser_WebAuthnName_Call
func (*MockUser_WebAuthnName_Call) Run ¶
func (_c *MockUser_WebAuthnName_Call) Run(run func()) *MockUser_WebAuthnName_Call
func (*MockUser_WebAuthnName_Call) RunAndReturn ¶
func (_c *MockUser_WebAuthnName_Call) RunAndReturn(run func() string) *MockUser_WebAuthnName_Call
type NewUser ¶
type NewUser struct {
Username string
UserID []byte
Credential webauthn.Credential
}
NewUser contains the data required to create a new registered user.
type Option ¶
type Option func(*Passkey)
func WithInsecureCookie ¶
func WithInsecureCookie() Option
WithInsecureCookie sets Cookie.Secure to false. This is useful for development. Do not use in production.
func WithLogger ¶
WithLogger sets the logger for the passkey instance.
func WithSessionCookieNamePrefix ¶
WithSessionCookieNamePrefix sets custom prefix for names of the session cookies instead of default.
func WithUserSessionMaxAge ¶
WithUserSessionMaxAge sets the max age of the user session cookie.
type Passkey ¶
type Passkey struct {
// contains filtered or unexported fields
}
func (*Passkey) Auth ¶
func (p *Passkey) Auth(userIDKey AuthUserIDKey, onSuccess, onFail http.HandlerFunc) func(next http.Handler) http.Handler
Auth adds a valid user session's ID to the context, or calls onFail. A nil onFail defaults to Unauthorized.
type RegistrationSessionData ¶
type RegistrationSessionData struct {
Username string
Session webauthn.SessionData
Expires time.Time
}
type SessionStore ¶
type SessionStore[T any] interface { Create(data T) (string, error) Delete(token string) Get(token string) (*T, bool) Consume(token string) (*T, bool) }
SessionStore is a storage for session data. Stores must use distinct key namespaces for each session type and application/tenant scope. Create must return a unique, cryptographically random token with at least 128 bits of entropy. Serialization must preserve all fields, including Purpose; adapters must not synthesize missing fields. Consume must atomically retrieve and delete the session identified by token to prevent replay. Get and Consume return (nil, false) for missing or expired records. Login and registration handlers consume ceremony sessions before verification, including failed attempts. Stores must bound retained records and reclaim expired entries before rejecting new sessions. Create returns ErrSessionStoreFull when capacity is exhausted; handlers enforce expiration independently.
type UserSessionData ¶
type UserStore ¶
type UserStore interface {
Create(u NewUser) (User, error)
// UpdateCredential atomically updates an existing credential's authentication state.
// Preserve registration data and other credentials; ignore updates with older counters.
// Retain previously observed clone warnings.
// Unknown users and credentials return ErrUserNotFound and ErrCredentialNotFound respectively.
UpdateCredential(userID []byte, credential webauthn.Credential) error
Get(userID []byte) (User, error)
GetByName(username string) (User, error)
}
UserStore is a persistent storage for users and credentials. Implementations of Create must atomically persist the account and its initial credential, preserving the exact UserID handle, and enforcing unique username and user ID. Create returns ErrUserAlreadyExists on conflicts; lookups return ErrUserNotFound for missing users. Reads and Create return detached snapshots, including credential byte slices. Errors may be logged; adapters must not include secrets or session tokens in them.