login

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname = loginapi.Hostname
	Version  = 92
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	Subject string   `json:"sub"`
	Roles   []string `json:"roles"`
}

Actor represents the authenticated user. It is parsed from the claims associated with the request.

func (Actor) HasRole

func (a Actor) HasRole(role string) bool

HasRole checks if the actor can claim the indicated role.

func (Actor) IsAdmin

func (a Actor) IsAdmin() bool

IsAdmin indicates if the actor can claim the admin role.

func (Actor) IsManager

func (a Actor) IsManager() bool

IsAdmin indicates if the can claim the manager role.

func (Actor) IsUser

func (a Actor) IsUser() bool

IsAdmin indicates if the actor can claim the user role.

func (*Actor) SetAdmin

func (a *Actor) SetAdmin()

SetAdmin claims the admin role for the actor.

func (*Actor) SetManager

func (a *Actor) SetManager()

SetManager claims the manager role for the actor.

func (*Actor) SetUser

func (a *Actor) SetUser()

SetUser claims the user role for the actor.

func (Actor) String

func (a Actor) String() string

String prints the actor as JSON.

type Intermediate added in v1.22.0

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate added in v1.22.0

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) AdminOnly added in v1.22.0

func (svc *Mock) AdminOnly(w http.ResponseWriter, r *http.Request) (err error)

AdminOnly executes the mock handler.

func (*Mock) Login added in v1.22.0

func (svc *Mock) Login(w http.ResponseWriter, r *http.Request) (err error)

Login executes the mock handler.

func (*Mock) Logout added in v1.22.0

func (svc *Mock) Logout(w http.ResponseWriter, r *http.Request) (err error)

Logout executes the mock handler.

func (*Mock) ManagerOnly added in v1.22.0

func (svc *Mock) ManagerOnly(w http.ResponseWriter, r *http.Request) (err error)

ManagerOnly executes the mock handler.

func (*Mock) MockAdminOnly added in v1.22.0

func (svc *Mock) MockAdminOnly(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockAdminOnly sets up a mock handler for AdminOnly.

func (*Mock) MockLogin added in v1.22.0

func (svc *Mock) MockLogin(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockLogin sets up a mock handler for Login.

func (*Mock) MockLogout added in v1.22.0

func (svc *Mock) MockLogout(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockLogout sets up a mock handler for Logout.

func (*Mock) MockManagerOnly added in v1.22.0

func (svc *Mock) MockManagerOnly(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockManagerOnly sets up a mock handler for ManagerOnly.

func (*Mock) MockWelcome added in v1.22.0

func (svc *Mock) MockWelcome(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockWelcome sets up a mock handler for Welcome.

func (*Mock) OnShutdown added in v1.22.0

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup added in v1.22.0

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Mock) Welcome added in v1.22.0

func (svc *Mock) Welcome(w http.ResponseWriter, r *http.Request) (err error)

Welcome executes the mock handler.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove
}

Service implements the login.example microservice.

The Login microservice demonstrates usage of authentication and authorization.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) AdminOnly

func (svc *Service) AdminOnly(w http.ResponseWriter, r *http.Request) (err error)

AdminOnly is only accessible by admins.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) Login

func (svc *Service) Login(w http.ResponseWriter, r *http.Request) (err error)

Login renders a simple login screen that authenticates a user. Known users are hardcoded as "admin", "manager" and "user". The password is "password".

func (*Service) Logout

func (svc *Service) Logout(w http.ResponseWriter, r *http.Request) (err error)

Logout renders a page that logs out the user.

func (*Service) ManagerOnly

func (svc *Service) ManagerOnly(w http.ResponseWriter, r *http.Request) (err error)

ManagerOnly is only accessible by managers.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) Welcome

func (svc *Service) Welcome(w http.ResponseWriter, r *http.Request) (err error)

Welcome renders a page that is shown to the user after a successful login. Rendering is adjusted based on the user's roles.

type ToDo added in v1.22.0

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	Login(w http.ResponseWriter, r *http.Request) (err error)       // MARKER: Login
	Logout(w http.ResponseWriter, r *http.Request) (err error)      // MARKER: Logout
	Welcome(w http.ResponseWriter, r *http.Request) (err error)     // MARKER: Welcome
	AdminOnly(w http.ResponseWriter, r *http.Request) (err error)   // MARKER: AdminOnly
	ManagerOnly(w http.ResponseWriter, r *http.Request) (err error) // MARKER: ManagerOnly
}

ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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