auth

package
v0.1.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package auth implements static bearer API keys with two roles. Keys are compared as SHA-256 digests in constant time.

Index

Constants

View Source
const SecretPrefix = "whsec_"

Variables

This section is empty.

Functions

func Sign

func Sign(secret, msgID string, ts time.Time, payload []byte) (string, error)

Sign produces the webhook-signature header value ("v1,<base64>").

func SignedHeaders

func SignedHeaders(secret, msgID string, ts time.Time, payload []byte) (map[string]string, error)

SignedHeaders returns the three Standard Webhooks headers for a delivery.

func VerifySignature

func VerifySignature(secret, msgID string, ts time.Time, payload []byte, header string, tolerance time.Duration, now time.Time) error

VerifySignature checks a webhook-signature header (space-separated list of "v1,<sig>" entries) in constant time. Used by tests and by receiver-side tooling.

Types

type Auth

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

func New

func New(keys []config.APIKey) *Auth

func (*Auth) Authenticate

func (a *Auth) Authenticate(r *http.Request) Role

Authenticate resolves the request's role. With no keys configured every request is admin.

func (*Auth) Open

func (a *Auth) Open() bool

Open reports whether no keys are configured (auth disabled).

type Role

type Role int
const (
	RoleNone Role = iota
	RoleWriter
	RoleAdmin
)

Jump to

Keyboard shortcuts

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