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
- type CreateUserInput
- type Credentials
- type Option
- type OrganizationService
- type Plugin
- func (p *Plugin) AdminRoleName() string
- func (p *Plugin) Bootstrap(ctx context.Context, creds Credentials) (bool, error)
- func (p *Plugin) CreateUser(ctx context.Context, in CreateUserInput) (*store.User, string, error)
- func (p *Plugin) Disable(ctx context.Context, userID string) (*store.User, error)
- func (p *Plugin) Enable(ctx context.Context, userID string) (*store.User, error)
- func (p *Plugin) ID() string
- func (p *Plugin) Register(r *plugin.Registry) error
- func (p *Plugin) ResetPassword(ctx context.Context, userID string, opts ResetOptions) (string, error)
- func (p *Plugin) SetRole(ctx context.Context, userID, role string) (*store.User, error)
- type ResetOptions
Constants ¶
const DefaultAdminRole = "admin"
DefaultAdminRole is the role that every administrative route requires.
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 ¶
AdminRole names the role that every administrative route requires. The default is "admin".
func Organizations ¶ added in v0.4.0
func Organizations(s OrganizationService) Option
Organizations adds the administrative organization routes. The value is the organizations plugin.
orgs := organizations.New(...) adm := admin.New(admin.Organizations(orgs))
type OrganizationService ¶ added in v0.4.0
type OrganizationService interface {
// AdminList returns one page of every organization of the application.
AdminList(ctx context.Context, limit int, cursor string) ([]store.Organization, string, error)
// AdminDelete removes one organization and every row that belongs to it.
AdminDelete(ctx context.Context, actor *store.User, orgID string) error
}
OrganizationService lists and removes the organizations of the whole application. The organizations plugin implements it.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is the admin plugin.
func (*Plugin) AdminRoleName ¶
AdminRoleName returns the configured administrator role.
func (*Plugin) Bootstrap ¶
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 ¶
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 ¶
Disable blocks every credential of one user and revokes every session of the user in the same transaction.
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.
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.