admin

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package admin adds user administration to Auth-All.

The plugin serves the administrative HTTP routes, and it exports the same operations as Go methods, so an operator task needs no HTTP request.

adm := admin.New(admin.AdminRole("admin"))
auth, err := authall.New(authall.WithStore(s),
    authall.WithPlugins(roles.New(roles.Hierarchy("viewer", "admin")), adm))
created, err := adm.Bootstrap(ctx, admin.Credentials{Email: e, Password: p})

Index

Constants

View Source
const DefaultAdminRole = "admin"

DefaultAdminRole is the role that every administrative route requires.

View Source
const ID = "admin"

ID is the stable plugin identifier.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateUserInput

type CreateUserInput struct {
	Email string
	Name  string
	// Role is the role of the new user. An empty value takes the default role.
	Role string
	// Password is the first password. An empty value generates one.
	Password string
	// TemporaryPassword makes the user change the password before it reaches
	// any protected route.
	TemporaryPassword bool
}

CreateUserInput describes a new user of an administrative operation.

type Credentials

type Credentials struct {
	Email    string
	Password string
	Name     string
	// TemporaryPassword makes the first administrator change the password
	// before it reaches any protected route. The default is false.
	TemporaryPassword bool
}

Credentials name the first administrator.

type Option

type Option func(*Plugin)

Option configures the plugin.

func AdminRole

func AdminRole(name string) Option

AdminRole names the role that every administrative route requires. The default is "admin".

type Plugin

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

Plugin is the admin plugin.

func New

func New(opts ...Option) *Plugin

New returns the admin plugin.

func (*Plugin) AdminRoleName

func (p *Plugin) AdminRoleName() string

AdminRoleName returns the configured administrator role.

func (*Plugin) Bootstrap

func (p *Plugin) Bootstrap(ctx context.Context, creds Credentials) (bool, error)

Bootstrap creates the first administrator when the users table is empty.

It returns false and changes nothing when any user exists. Two instances can call it at the same time, and at most one user appears, because the guard row has one primary key.

Auth-All never calls Bootstrap on its own. Construction has no side effect, so a replica start changes no user.

func (*Plugin) CreateUser

func (p *Plugin) CreateUser(ctx context.Context, in CreateUserInput) (*store.User, string, error)

CreateUser creates a user with a role and a password.

It returns the generated password when the caller supplied none. The password exists in this return value only.

func (*Plugin) Disable

func (p *Plugin) Disable(ctx context.Context, userID string) (*store.User, error)

Disable blocks every credential of one user and revokes every session of the user in the same transaction.

func (*Plugin) Enable

func (p *Plugin) Enable(ctx context.Context, userID string) (*store.User, error)

Enable removes the disabled state of one user.

func (*Plugin) ID

func (p *Plugin) ID() string

ID implements plugin.Plugin.

func (*Plugin) Register

func (p *Plugin) Register(r *plugin.Registry) error

Register implements plugin.Plugin.

func (*Plugin) ResetPassword

func (p *Plugin) ResetPassword(ctx context.Context, userID string, opts ResetOptions) (string, error)

ResetPassword sets a new password for one user and revokes every session of the user. It returns the generated password when the caller supplied none.

func (*Plugin) SetRole

func (p *Plugin) SetRole(ctx context.Context, userID, role string) (*store.User, error)

SetRole sets the role of one user.

type ResetOptions

type ResetOptions struct {
	// Password is the new password. An empty value generates one.
	Password string
	// Temporary makes the user change the password before it reaches any
	// protected route.
	Temporary bool
}

ResetOptions describe a password reset by an administrator.

Jump to

Keyboard shortcuts

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