authz

package
v0.10.1 Latest Latest
Warning

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

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

Documentation

Overview

Package authz calls auth-api's POST /authz/check to verify a caller's bearer token and resolve their roles, and provides Gin middleware that gates a route on holding one of a set of allowed roles. See platform's api-client-auth spec (openspec/changes/api-client-auth in sweetrpg/platform).

Index

Constants

View Source
const (
	RoleUser      = "user"
	RoleSubmitter = "submitter"
	RoleEditor    = "editor"
	RoleModerator = "moderator"
	RoleApprover  = "approver"
	RoleAdmin     = "admin"
)

Platform role names, matching auth-api's fixed role model exactly (see openspec/specs/user-authorization/spec.md's "Role model" requirement).

Variables

This section is empty.

Functions

func HasRole

func HasRole(roles []string, want string) bool

HasRole reports whether roles contains want.

Types

type CheckResponse

type CheckResponse struct {
	Allowed bool     `json:"allowed"`
	Roles   []string `json:"roles"`
	Sub     string   `json:"sub"`
	Reason  string   `json:"reason"`
}

CheckResponse is the union of auth-api's allowed/denied /authz/check response shapes.

type Client

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

Client calls auth-api's /authz/check endpoint.

func NewClient

func NewClient(baseURL string) *Client

NewClient builds a Client against auth-api's base URL (e.g. http://api-v1.sweetrpg-auth.svc.cluster.local:8000). An empty baseURL is accepted so the service can still start when AUTH_API_URL isn't configured; every Check call will then fail with a transport error, which RequireAnyRole surfaces as a 503.

func (*Client) Check

func (c *Client) Check(ctx context.Context, token, service string) (*CheckResponse, error)

Check verifies token against auth-api and returns the caller's allowed/roles/subject for the given service name. Returns InvalidTokenError if auth-api rejects the token itself.

type InvalidTokenError

type InvalidTokenError struct{}

InvalidTokenError means auth-api rejected the bearer token itself (missing, expired, unverifiable) - distinct from a service-level deny (Allowed: false with a Reason) or a transport/backend failure.

func (InvalidTokenError) Error

func (InvalidTokenError) Error() string

Jump to

Keyboard shortcuts

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