- rbac/: Role type, constants, HasPermission, RoleFromString - blocks/: BlockFunc, BlockMeta, BlockContext, context accessors, BlockRegistry interface - templates/: TemplateFunc, meta types, TemplateRegistry interface - auth/: Claims, PublicClaims, context extractors - content/: Content interface, AuthorProfile/PageInfo/PostInfo types - settings/: Settings interface, map accessor helpers - gating/: AccessRule, AccessResult, EvaluateAccess, Gating interface - crypto/: Crypto interface (Encrypt/Decrypt) - render/: BlockNoteToHTML standalone renderer - video/: ParseEmbedURL, EmbedIframeURL - ai/: ToolDefinition, ToolResult, ToolRegistry interface Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package auth
|
|
|
|
import "context"
|
|
|
|
type contextKey string
|
|
|
|
const (
|
|
userContextKey contextKey = "user"
|
|
publicUserContextKey contextKey = "public_user"
|
|
)
|
|
|
|
// GetUserFromContext retrieves admin user claims from context.
|
|
func GetUserFromContext(ctx context.Context) (*Claims, bool) {
|
|
claims, ok := ctx.Value(userContextKey).(*Claims)
|
|
return claims, ok
|
|
}
|
|
|
|
// GetPublicUserFromContext retrieves public user claims from context.
|
|
func GetPublicUserFromContext(ctx context.Context) (*PublicClaims, bool) {
|
|
claims, ok := ctx.Value(publicUserContextKey).(*PublicClaims)
|
|
return claims, ok
|
|
}
|
|
|
|
// WithUser adds admin user claims to context.
|
|
// Used by CMS auth middleware — not typically called by plugins.
|
|
func WithUser(ctx context.Context, claims *Claims) context.Context {
|
|
return context.WithValue(ctx, userContextKey, claims)
|
|
}
|
|
|
|
// WithPublicUser adds public user claims to context.
|
|
// Used by CMS auth middleware — not typically called by plugins.
|
|
func WithPublicUser(ctx context.Context, claims *PublicClaims) context.Context {
|
|
return context.WithValue(ctx, publicUserContextKey, claims)
|
|
}
|