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

testauth

package
v0.111.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testauth is an auth.Authenticator for ContentKit's package tests, which cannot import a real provider: a request's bearer names its actor (As) and an Authorizer answers its Can. The end-to-end suite (e2e/) runs the same gates against a real AuthKit.

Index

Constants

View Source
const Issuer = "https://auth.test"

Issuer is the test credentials' issuer.

Variables

View Source
var Scope = auth.Scope{Authority: Issuer, ID: "root"}

Scope is the test Authenticator's root scope, where staff hold their permissions.

Functions

func Actor

func Actor(a access.Actor, authz Authorizer) access.Actor

Actor is a as the gate builds it, with a Verified answering Can by authz, for calls that take an actor directly.

func As

func As(r *http.Request, a access.Actor) *http.Request

As is r sent by a: a signed-in actor's bearer, and a.IP as the peer address.

func Token

func Token(a access.Actor) string

Token is the bearer As sends for a signed-in actor.

func Verify

func Verify(a access.Actor, authz Authorizer) (auth.Verified, error)

Verify is what an Authenticator says of a request sent by a: anonymous is auth.ErrUnauthenticated, any other a Verified answering Can by authz.

Types

type All

type All struct{}

All holds every permission.

func (All) Can

type Auth

type Auth struct {
	Authz  Authorizer
	Claims map[string][]string
}

Auth authenticates "Bearer user:{id}" and "Bearer app:{id}"; any other bearer is refused. Authz answers Can in Scope; nil holds nothing. Claims are a subject's token entitlement claims (access.Entitled).

func (Auth) Authenticate

func (a Auth) Authenticate(r *http.Request) (auth.Verified, error)

func (Auth) RootScope

func (Auth) RootScope(context.Context) (auth.Scope, error)

RootScope is Scope (authkit/auth Root).

type Authorizer

type Authorizer interface {
	Can(ctx context.Context, a access.Actor, perm string) (bool, error)
}

Authorizer decides a test actor's permissions in Scope.

type None

type None struct{}

None holds nothing.

func (None) Can

type ScopedAuthorizer added in v0.81.0

type ScopedAuthorizer interface {
	CanIn(ctx context.Context, a access.Actor, scope auth.Scope, perm string) (bool, error)
}

ScopedAuthorizer, when an Authorizer is one, decides in every scope, not only Scope: AuthKit group scopes.

Jump to

Keyboard shortcuts

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