client

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 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

Authentication and Authorization Middleware

Middleware for IDs

Index

Constants

View Source
const (
	SubjectTenantCreated = "tenant.notify.created"
	SubjectTenantUpdated = "tenant.notify.updated"
	SubjectTenantDeleted = "tenant.notify.deleted"
)

NATS subjects published by the admin service for tenant lifecycle events. Subscribers (e.g., media-server) react to these to keep tenant-scoped resources in sync with the admin account store.

Variables

View Source
var (
	ENDPOINT_KINDS = []string{
		"login_service",
		"admin_service",
		"proxy_service",
		"messenger_service",
		"blackbox_service",
		"media_service",
		"queue_service",
		"controller_service",
		"host_service",
		"comms_service",
		"proxy",
	}
)

Functions

func AccountIDFromContext

func AccountIDFromContext(ctx context.Context) string

Account ID

func AccountPublicKeyFromContext

func AccountPublicKeyFromContext(ctx context.Context) string

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) *user.UserClaims

ClaimsFromContext returns the validated user claims attached by the Bearer middleware, or nil if the request was not bearer-authenticated. The claims are stored as *user.UserClaims (see Bearer/BasicOrBearer), so this must assert that concrete type.

func EndpointKinds

func EndpointKinds() []string

func InKind

func InKind(kind string) bool

func NoAuthFromContext

func NoAuthFromContext(ctx context.Context) bool

If notoken is attached to the context, there was no token attached to the request.

func UserIDFromContext

func UserIDFromContext(ctx context.Context) string

User ID

func ValidBasicAuthFromContext

func ValidBasicAuthFromContext(ctx context.Context) bool

Is the user valid - from Basis Authentication with email:password.

func ValidTokenFromContext

func ValidTokenFromContext(ctx context.Context) bool

Does the request have a valid token?

Types

type Auth

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

Store is optional when middleware is used by distributed service API endpoint - validates JWTs issued by trusted accounts. Authorization using JWT claims.

func NewAuth

func NewAuth(authConfig AuthConfig) *Auth

NewAuth returns a *Auth. It returns a pointer (not a value) because Auth contains a sync.RWMutex and must not be copied.

func (*Auth) AddTrustedAccount

func (auth *Auth) AddTrustedAccount(id string)

func (*Auth) Basic

func (auth *Auth) Basic(h http.HandlerFunc) http.HandlerFunc

Basic Auth Only

func (*Auth) BasicOrBearer

func (auth *Auth) BasicOrBearer(h http.HandlerFunc) http.HandlerFunc

Basic -or- Bearer

func (*Auth) Bearer

func (auth *Auth) Bearer(h http.HandlerFunc) http.HandlerFunc

Bearer Auth Only

func (*Auth) IsPublicKeyTrusted

func (auth *Auth) IsPublicKeyTrusted(publicKey string) bool

func (*Auth) RequireAdmin

func (auth *Auth) RequireAdmin(adminAccountID string, h http.HandlerFunc) http.HandlerFunc

RequireAdmin wraps a Bearer-authenticated handler and allows users from the ADMIN account (super admins) or users with the administrator role in any account. Returns 403 for all other users.

func (*Auth) RequireRole

func (auth *Auth) RequireRole(adminAccountID string, role string, h http.HandlerFunc) http.HandlerFunc

RequireRole wraps a Bearer-authenticated handler and allows users from the ADMIN account (super admins) or users with the specified role in any account. Uses user.HasRole which accepts both singular and legacy plural role names. Returns 403 for all other users.

func (*Auth) RequireSuperAdmin

func (auth *Auth) RequireSuperAdmin(adminAccountID string, h http.HandlerFunc) http.HandlerFunc

RequireSuperAdmin wraps a Bearer-authenticated handler and only allows users from the ADMIN account. Returns 403 for all other users.

func (*Auth) SetStore

func (auth *Auth) SetStore(st IdentityStore)

SetStore attaches an admin Store handle to the auth middleware so RequireRole can look up users by their NATS public key and check their roles. Used by services that share a process with the admin server (the media server, for example) and need to gate handlers by the user's role on their own tenant account, not just by whether the caller is in the super-admin ADMIN account.

type AuthConfig

type AuthConfig struct {
	BasicAuth       bool
	Store           IdentityStore
	Logger          *logger.Logger
	TrustedAccounts []string
}

type AuthContextKey

type AuthContextKey struct {
	Key string
}

type EndpointHealth

type EndpointHealth struct {
}

type ID

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

func NewID

func NewID(idConfig IDConfig) ID

func (*ID) Middleware

func (id *ID) Middleware(next http.Handler) http.Handler

Prefer variables in headers "X-Blackbox-{}". Next look in query parameters.

type IDConfig

type IDConfig struct {
	BasicAuth bool
	Store     IdentityStore
	Logger    *logger.Logger
}

type IDContextKey

type IDContextKey struct {
	Key string
}

type IdentityStore

type IdentityStore interface {
	GetUserByEmail(email string) (*user.User, string, error)
	GetUserByPublicKey(accountID, publicKey string) (*user.User, error)
	GetActivity(accountID, activityID string) (user.Activity, error)
	UpdateActivity(accountID string, a user.Activity) error
	PutActivity(accountID string, activity user.Activity) error
	ValidateUserPassword(accountID, userID, password string) (bool, error)
}

IdentityStore is the slice of the admin store that the Auth and ID middleware need: password validation and lockout accounting for basic auth, and user lookup for role checks. *admin.Store satisfies it. Services that only validate bearer tokens issued by trusted accounts do not need one at all.

type ServiceEndpoint

type ServiceEndpoint struct {
	Kind      string         `json:"kind"`
	URL       string         `json:"url"`
	Health    EndpointHealth `json:"health"`
	ProxyHost string         `json:"proxy_host,omitempty"`
	ProxyPort int            `json:"proxy_port,omitempty"`
}

func NewServiceEndpoint

func NewServiceEndpoint(kind string, url string) ServiceEndpoint

type ServiceEndpoints

type ServiceEndpoints []ServiceEndpoint

func (*ServiceEndpoints) AddEndpoint

func (serviceEndpoints *ServiceEndpoints) AddEndpoint(kind string, url string) error

func (*ServiceEndpoints) ByKind

func (serviceEndpoints *ServiceEndpoints) ByKind(kind string) *[]ServiceEndpoint

type TenantCreatedNotification

type TenantCreatedNotification struct {
	AccountID   string `json:"accountId"`
	AccountName string `json:"accountName"`
	Timestamp   int64  `json:"timestamp"`
}

TenantCreatedNotification is published when a new account is created.

type TenantDeletedNotification

type TenantDeletedNotification struct {
	AccountID   string `json:"accountId"`
	AccountName string `json:"accountName"`
	Timestamp   int64  `json:"timestamp"`
}

TenantDeletedNotification is published when an account is deleted. AccountName carries the last-known name since the account record is gone by the time subscribers receive this.

type TenantUpdatedNotification

type TenantUpdatedNotification struct {
	AccountID    string `json:"accountId"`
	AccountName  string `json:"accountName"`
	PreviousName string `json:"previousName,omitempty"`
	Timestamp    int64  `json:"timestamp"`
}

TenantUpdatedNotification is published when an account's mutable fields (name, description, etc.) change. PreviousName is set when a rename occurred so subscribers can map old → new resources.

Jump to

Keyboard shortcuts

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