identity

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package identity carries the caller's authenticated identity on a request's context, from the authentication middleware that resolves it to the handlers that act on it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, identity Identity) context.Context

NewContext returns a copy of ctx carrying identity. Every handler downstream trusts it as the authenticated caller, so only the authentication middleware calls it outside tests.

Types

type Identity

type Identity struct {
	ID        string
	Username  string
	TenantID  string
	DeviceUID string
	APIKey    string
	APIKeyID  string
	Role      authorizer.Role
	Admin     bool
	AdminID   string
}

Identity is the caller's authenticated identity, as resolved from the request's credential.

func FromContext

func FromContext(ctx context.Context) (Identity, bool)

FromContext returns the identity NewContext stored on ctx, and false when the request is anonymous or never went through authentication.

func (*Identity) WithoutUserScope

func (i *Identity) WithoutUserScope() Identity

WithoutUserScope returns the identity stripped of the acting user's ID and namespace scope, keeping the admin flag. An administrator's ID moves to AdminID, so an admin route can still tell who acted without the ID the guards key on.

The /admin/api surface depends on this shape: the authorization middleware treats a missing ID alongside Admin as "this call came from the admin panel rather than from a namespace member", and lets it past the tenant guard. An admin hitting the regular /api surface keeps their user scope and stays subject to that guard.

Directories

Path Synopsis
Package identitytest stands in for the authentication middleware in tests that drive a router built without it.
Package identitytest stands in for the authentication middleware in tests that drive a router built without it.

Jump to

Keyboard shortcuts

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