auth

package
v0.0.0-...-bea47b1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 1 Imported by: 0 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.

README

Auth System - Flexible Authorization

Ultra-minimal, pluggable authorization interface. Bring your own auth!

Interface

type AuthProvider interface {
    CheckAccess(ctx context.Context, resource string, action string) error
}

That's it! Use context.Context however you want.

Quick Start

1. No Auth (Default)
engine := flow.NewEngine(storage, registry)
// No auth set = everything allowed
2. Simple Auth
type MyAuth struct{}

func (a *MyAuth) CheckAccess(ctx context.Context, resource string, action string) error {
    userID := ctx.Value("user_id").(string)
    // Your logic
    return nil
}

engine.SetAuthProvider(&MyAuth{})
3. Multi-Tenant
func (a *MyAuth) CheckAccess(ctx context.Context, resource string, action string) error {
    customerID := ctx.Value("customer_id").(string)
    userID := ctx.Value("user_id").(string)
    
    // Get workflow
    workflow := getFromDB(resource)
    
    // CRITICAL: Tenant isolation
    if workflow.Metadata["customer_id"] != customerID {
        return errors.New("forbidden")
    }
    
    // Check permissions
    if workflow.Metadata["owner_id"] == userID {
        return nil
    }
    
    return errors.New("forbidden")
}

Store Auth Data

wf := &flow.Workflow{
    ID: "my-workflow",
    Metadata: map[string]interface{}{
        // Use ANY field names - we don't enforce structure!
        "customer_id": "acme-corp",
        "user_id": "user-123",
        "owner": "john@acme.com",
        "team_id": "eng",
        "visibility": "team",
        
        // Or Firebase, Auth0, etc.
        "firebase_uid": "abc123",
        "auth0_org": "org_xyz",
    },
}

Actions

Common actions (define your own):

  • "create" - Register workflow
  • "view" - View definition
  • "execute" - Trigger execution
  • "edit" - Modify workflow
  • "delete" - Delete workflow

Full Example

See examples/auth/main.go for complete multi-tenant implementation.

Key Principles

  1. Fully pluggable - Use any auth system
  2. No structure enforced - Use any field names
  3. Context-based - Pass auth via context
  4. Metadata is flexible - Store anything

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthProvider

type AuthProvider interface {
	// CheckAccess checks if action is allowed on resource
	// Use context to pass whatever you need (user_id, tenant_id, slug, JWT, etc.)
	//
	// Examples:
	//   CheckAccess(ctx, "workflow:my-flow", "execute")
	//   CheckAccess(ctx, "workflow:my-flow", "edit")
	//   CheckAccess(ctx, "execution:abc-123", "view")
	//
	// Return nil if allowed, error if denied
	CheckAccess(ctx context.Context, resource string, action string) error
}

AuthProvider is the interface for authorization Implement this with YOUR auth system - we don't care how

type NoAuth

type NoAuth struct{}

NoAuth allows everything - for dev/testing

func (*NoAuth) CheckAccess

func (n *NoAuth) CheckAccess(ctx context.Context, resource string, action string) error

Jump to

Keyboard shortcuts

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