Skip to content
Token Management

Token Management

Token Management issues API access tokens. Other applications use a token to call your REST endpoints as an authenticated subject. Like a user, a token can carry roles, groups and permissions.

Access tokens

Enable

tokens := std.Must(cfg.TokenManagement()) // application.TokenManagement

Token Management is not part of StandardSystems. It enables User, Group and Role Management and registers tokens as a ReBAC resource. application.TokenManagement has the fields UseCases token.UseCases and Pages uitoken.Pages with the path Tokens.

Protect an endpoint

Use AuthenticateSubject with hapi.BearerAuth to resolve the bearer token of a request into a subject, see REST APIs:

hapi.Post[Request](api, hapi.Operation{Path: "/api/v1/events"}).
	Request(
		hapi.BearerAuth[Request](tokens.UseCases.AuthenticateSubject, func(dst *Request, subject auth.Subject) error {
			dst.Subject = subject
			return nil
		}),
	).
	Response(hapi.ToJSON[Request, Response](handleEvent))

handleEvent checks the permissions of in.Subject like any other use case. A request without an Authorization header gets an anonymous subject.

Use cases

Use caseDescription
CreateCreates a token. The plaintext is returned once and never stored.
RotateIssues a new secret for a token and keeps its settings.
DeleteDeletes a token; a subject can always delete its own tokens.
FindAllLists the visible tokens.
FindByIDLoads a token.
AuthenticateSubjectReturns the subject of a plaintext token; it is invalid if the token is unknown or expired.

ResolveTokenRights is deprecated, use the ReBAC API.

Permissions

PermissionAllows to
nago.token.createcreate tokens
nago.token.rotaterotate tokens
nago.token.deletedelete tokens
nago.token.find_alllist tokens
nago.token.resolve_token_rightsview the rights of a token

UI

The page admin/iam/tokens creates, rotates and deletes tokens. The admin center shows the card Access Token in the group Access Tokens to users with nago.token.find_all.

Related