relations

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package relations is the client for auth-api's POST /authz/check-relation (PADR-0035).

The caller's own bearer token is forwarded on every call (PADR-0037, no service tokens), so a check only answers for the user holding that token. Only positive decisions are cached, for a few seconds, so a removal takes effect within positiveTTL and a new grant at once. Any failure to get a decision is an error: session data fails closed (503), never open.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable means auth-api or OpenFGA could not give a decision. Callers answer 503.
	ErrUnavailable = errors.New("relations: authorization unavailable")
	// ErrUnauthorized means auth-api rejected the user's token. Callers answer 401.
	ErrUnauthorized = errors.New("relations: token rejected")
	// ErrDenied means auth-api refused the change: the caller lacks the relation, or is denied
	// the service. Callers answer 403.
	ErrDenied = errors.New("relations: not permitted")
	// ErrLimited means auth-api's mint or tuple limits stopped the call. Callers answer 429.
	ErrLimited = errors.New("relations: rate limited")
	// ErrConflict means auth-api refused the change as conflicting (the session's tuple cap).
	// Callers answer 409.
	ErrConflict = errors.New("relations: conflict")
	// ErrRejected means auth-api answered 400: this service sent a malformed request, so retrying
	// the same call never helps. Callers answer 500.
	ErrRejected = errors.New("relations: request rejected as malformed")
)

Functions

This section is empty.

Types

type Client

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

Client calls auth-api. The zero value is not usable; use New.

func New

func New(baseURL string) *Client

New returns a Client for the auth-api base URL.

func (*Client) Check

func (c *Client) Check(ctx context.Context, user, token, object, relation string) (bool, error)

Check reports whether the holder of token has relation on object (for example "session:abc", "can_view"). user is the verified caller ID and only keys the cache; auth-api decides from the token. A deny is (false, nil).

func (*Client) EndSession added in v0.3.0

func (c *Client) EndSession(ctx context.Context, token, sessionID string) error

EndSession deletes every tuple on the session and closes its mint. Only the GM may.

func (*Client) Mint added in v0.3.0

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

Mint asks auth-api for a new session ID and writes the caller's gm tuple on it. The ID comes from auth-api, never from the client (PADR-0040).

func (*Client) WriteTuples added in v0.3.0

func (c *Client) WriteTuples(ctx context.Context, token, sessionID string, writes, deletes []Tuple) error

WriteTuples applies membership tuple changes on one session in a single atomic write. Writing a tuple that exists and deleting one that does not are no-ops, so a retry is safe.

type Tuple added in v0.3.0

type Tuple struct {
	User     string `json:"user"` // "user:<canonical id>"
	Relation string `json:"relation"`
}

Tuple is one membership relation, written for the session object the call names.

Jump to

Keyboard shortcuts

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