auth

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: Apache-2.0 Imports: 11 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.

Documentation

Index

Constants

View Source
const (
	ApiKeyHeader = "X-API-Key"
	ApiKeyQuery  = "api-key"
)

Variables

This section is empty.

Functions

func GetRequestToken

func GetRequestToken(r *http.Request) string

Returns token from the request, checking for the X-API-Key header first

func RequireScope

func RequireScope(w http.ResponseWriter, r *http.Request, fn func(w http.ResponseWriter, r *http.Request) error, scopes ...string) error

Returns the API token from the request, checking for the X-API-Key header first and then the api-key query parameter (not recommended)

Types

type Manager

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

func New

func New(ctx context.Context, conn pg.PoolConn, opt ...Opt) (*Manager, error)

Create a new auth manager, with a root user

func (*Manager) Authenticate

func (manager *Manager) Authenticate(r *http.Request) (*schema.User, error)

Return a "live" user for a HTTP request

func (*Manager) Authorize

func (manager *Manager) Authorize(ctx context.Context, user *schema.User, scopes ...string) error

Authorize the user against scopes

func (*Manager) CreateToken

func (manager *Manager) CreateToken(ctx context.Context, name string, meta schema.TokenMeta) (*schema.Token, error)

Create a new token for a user

func (*Manager) CreateUser

func (manager *Manager) CreateUser(ctx context.Context, meta schema.UserMeta) (*schema.User, error)

Create a new user

func (*Manager) DeleteToken

func (manager *Manager) DeleteToken(ctx context.Context, name string, id uint64, force bool) (*schema.Token, error)

Delete or archive token for a user

func (*Manager) DeleteUser

func (manager *Manager) DeleteUser(ctx context.Context, name string, force bool) (*schema.User, error)

Archive or delete a user

func (*Manager) GetToken

func (manager *Manager) GetToken(ctx context.Context, name string, id uint64) (*schema.Token, error)

Get a token for a user

func (*Manager) GetUser

func (manager *Manager) GetUser(ctx context.Context, name string) (*schema.User, error)

Get a user

func (*Manager) GetUserForToken

func (manager *Manager) GetUserForToken(ctx context.Context, token string) (*schema.User, error)

Return a user for a token value

func (*Manager) ListTokens

func (manager *Manager) ListTokens(ctx context.Context, name string, req schema.TokenListRequest) (*schema.TokenList, error)

List tokens for a user

func (*Manager) ListUsers

func (manager *Manager) ListUsers(ctx context.Context, req schema.UserListRequest) (*schema.UserList, error)

List users

func (*Manager) ReplaceUser

func (manager *Manager) ReplaceUser(ctx context.Context, meta schema.UserMeta) (*schema.User, error)

Create a new user, or update if the name already exists

func (*Manager) UnarchiveUser

func (manager *Manager) UnarchiveUser(ctx context.Context, name string) (*schema.User, error)

Unarchive a user

func (*Manager) UpdateToken

func (manager *Manager) UpdateToken(ctx context.Context, name string, id uint64, meta schema.TokenMeta) (*schema.Token, error)

Update a token

func (*Manager) UpdateUser

func (manager *Manager) UpdateUser(ctx context.Context, name string, meta schema.UserMeta) (*schema.User, error)

Update a user

type Opt

type Opt func(*opts) error

Opt is a function which applies options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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