Help us shape the future of Go! Take the 2026 Go Developer Survey

mpclient

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mpclient calls the managed-principal API that SystemAuth serves to relying parties (systemauthsvc.ManagedPrincipalsPath). Every call acts as the signed-in manager and takes that manager's SystemAuth access token, granted the systemforge:managed_principals scope; the API takes the application from the token's client.

The package depends on the standard library and uuid only, so an application in another process does not import SystemAuth's storage.

Index

Constants

View Source
const (
	RoleGuardian = "guardian"
	RoleEducator = "educator"
)

Roles a manager can hold. Deployments may register further roles.

Variables

View Source
var (
	// ErrUnauthorized means the access token is missing, invalid or expired.
	ErrUnauthorized = errors.New("mpclient: unauthorized")
	// ErrForbidden means the manager may not do this, the principal does not
	// exist or is not theirs, or the token lacks the scope. The API gives one
	// answer for all of these.
	ErrForbidden = errors.New("mpclient: forbidden")
	// ErrNotFound means the route or a token, session or invitation was not
	// found.
	ErrNotFound = errors.New("mpclient: not found")
	// ErrInvalidCode means a claim code or invitation token cannot be used,
	// for any reason.
	ErrInvalidCode = errors.New("mpclient: invalid code")
	// ErrInvalidRequest means the request was refused as malformed or
	// incomplete; APIError.Message says why.
	ErrInvalidRequest = errors.New("mpclient: invalid request")
	// ErrConflict means the request conflicts with the principal's state,
	// such as removing its last manager.
	ErrConflict = errors.New("mpclient: conflict")
	// ErrRateLimited means too many attempts; APIError.RetryAfter says when
	// to try again.
	ErrRateLimited = errors.New("mpclient: rate limited")
)

Errors an API call can return, each wrapped in an *APIError.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status     int
	Message    string
	RetryAfter time.Duration
	// contains filtered or unexported fields
}

APIError is an unsuccessful response.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

Unwrap returns the Err* value matching the status, or nil.

type Claim

type Claim struct {
	ID        uuid.UUID `json:"id"`
	Code      string    `json:"code"`
	ExpiresAt time.Time `json:"expires_at"`
}

Claim is a single-use code that lets another person become a guardian.

type Client

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

Client calls the managed-principal API.

func New

func New(baseURL string, hc *http.Client) *Client

New returns a Client for the API at baseURL, such as "https://auth.example.com/managed-principals". A nil hc uses http.DefaultClient.

func (*Client) AcceptInvitation

func (c *Client) AcceptInvitation(ctx context.Context, token, invitation string) (uuid.UUID, error)

AcceptInvitation accepts an invitation to be managed and returns the new manager's ID.

func (*Client) Create

func (c *Client) Create(ctx context.Context, token string, in CreateInput) (uuid.UUID, error)

Create creates a managed principal with the caller as its only manager and returns its ID.

func (*Client) DeclineInvitation

func (c *Client) DeclineInvitation(ctx context.Context, token, invitation string) error

DeclineInvitation declines an invitation to be managed.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, token string, id uuid.UUID) error

Delete deletes a managed principal.

func (*Client) InviteManager

func (c *Client) InviteManager(ctx context.Context, token, email, role string) (*Invitation, error)

InviteManager offers to manage the person with a verified address, in role.

func (*Client) IssueClaim

func (c *Client) IssueClaim(ctx context.Context, token string, id uuid.UUID) (*Claim, error)

IssueClaim issues a single-use claim code for a managed principal.

func (*Client) IssueLoginToken

func (c *Client) IssueLoginToken(ctx context.Context, token string, id uuid.UUID, in IssueLoginTokenInput) (*IssuedLoginToken, error)

IssueLoginToken issues a login token for a managed principal.

func (*Client) List

func (c *Client) List(ctx context.Context, token string, after uuid.UUID, limit int) ([]ManagedPrincipal, error)

List returns a page of the caller's managed principals in principal-ID order, after the given ID (uuid.Nil for the first page). A short or empty page is the last. limit 0 uses the server's maximum.

func (*Client) ListLoginTokens

func (c *Client) ListLoginTokens(ctx context.Context, token string, id uuid.UUID) ([]LoginToken, error)

ListLoginTokens returns a managed principal's live login tokens.

func (*Client) ListManagers

func (c *Client) ListManagers(ctx context.Context, token string, id uuid.UUID) ([]Manager, error)

ListManagers returns a managed principal's active managers.

func (*Client) ListSessions

func (c *Client) ListSessions(ctx context.Context, token string, id uuid.UUID) ([]Session, error)

ListSessions returns the ways a managed principal is signed in.

func (*Client) RedeemClaim

func (c *Client) RedeemClaim(ctx context.Context, token, code string) (uuid.UUID, error)

RedeemClaim redeems a claim code: the caller becomes a guardian of the principal it names, whose ID is returned.

func (*Client) Release

func (c *Client) Release(ctx context.Context, token string, id uuid.UUID) error

Release ends management of a principal that has a verified email.

func (*Client) RemoveManager

func (c *Client) RemoveManager(ctx context.Context, token string, id, managerID uuid.UUID, role string) error

RemoveManager ends a manager's role over a managed principal. The last manager of a principal without a verified email cannot be removed.

func (*Client) RevokeAll

func (c *Client) RevokeAll(ctx context.Context, token string, id uuid.UUID) error

RevokeAll revokes every login token and session of a managed principal.

func (*Client) RevokeInvitation

func (c *Client) RevokeInvitation(ctx context.Context, token string, invitationID uuid.UUID) error

RevokeInvitation withdraws an invitation the caller made.

func (*Client) RevokeLoginToken

func (c *Client) RevokeLoginToken(ctx context.Context, token string, id, credentialID uuid.UUID) error

RevokeLoginToken revokes one login token.

func (*Client) RevokeSession

func (c *Client) RevokeSession(ctx context.Context, token string, id uuid.UUID, kind string, sessionID uuid.UUID) error

RevokeSession ends one session of the given kind.

type CreateInput

type CreateInput struct {
	DisplayName string
	// Email optionally gives the principal an unverified address.
	Email string
	Role  string
}

CreateInput describes a managed principal to create. The caller becomes its manager in Role.

type Invitation

type Invitation struct {
	ID        uuid.UUID `json:"id"`
	Token     string    `json:"token"`
	Email     string    `json:"email"`
	Role      string    `json:"role"`
	ExpiresAt time.Time `json:"expires_at"`
}

Invitation is an offer to manage a person with a verified address.

type IssueLoginTokenInput

type IssueLoginTokenInput struct {
	// Name optionally labels the token, such as the card or device.
	Name string `json:"name,omitempty"`
	// SingleUse makes the token valid for one sign-in.
	SingleUse bool `json:"single_use,omitempty"`
	// ExpiresAt optionally sets the expiry; the server clamps it to its
	// ceiling. Nil uses the client's or the deployment's default.
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

IssueLoginTokenInput describes a login token to issue.

type IssuedLoginToken

type IssuedLoginToken struct {
	ID        uuid.UUID  `json:"id"`
	Token     string     `json:"token"`
	Prefix    string     `json:"prefix"`
	SingleUse bool       `json:"single_use"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

IssuedLoginToken is a newly issued login token. Token is returned only once; render it as a code or card and do not store it.

type LoginToken

type LoginToken struct {
	ID         uuid.UUID  `json:"id"`
	Prefix     string     `json:"prefix"`
	Name       string     `json:"name,omitempty"`
	IssuedBy   uuid.UUID  `json:"issued_by"`
	SingleUse  bool       `json:"single_use"`
	CreatedAt  time.Time  `json:"created_at"`
	ExpiresAt  *time.Time `json:"expires_at,omitempty"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	LastUsedIP string     `json:"last_used_ip,omitempty"`
}

LoginToken is a live login token, without its value.

type ManagedPrincipal

type ManagedPrincipal struct {
	PrincipalID uuid.UUID `json:"principal_id"`
	DisplayName string    `json:"display_name"`
	// Roles are the roles the calling manager holds over it.
	Roles []string `json:"roles"`
}

ManagedPrincipal is a managed principal as its manager lists it.

type Manager

type Manager struct {
	PrincipalID uuid.UUID `json:"principal_id"`
	Role        string    `json:"role"`
}

Manager is a manager relationship.

type Session

type Session struct {
	ID         uuid.UUID  `json:"id"`
	Kind       string     `json:"kind"`
	Provider   string     `json:"provider,omitempty"`
	ClientID   string     `json:"client_id,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	ExpiresAt  time.Time  `json:"expires_at"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	ClientIP   string     `json:"client_ip,omitempty"`
}

Session is one way a managed principal is signed in. Kind is "login", "oauth" or "principal_token".

Jump to

Keyboard shortcuts

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