auth

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeAuthProvider cloudlib.ProviderType = 40

	// anonymous
	ScopeAnonymous = "api:anonymous" // this basically means that the Client is unknown
	// default API scopes
	ScopeApiRead   = "api:read" // that's the very minimum for a proper client
	ScopeApiWrite  = "api:write"
	ScopeApiEdit   = "api:edit"
	ScopeApiCreate = "api:create"
	ScopeApiDelete = "api:delete"
	ScopeApiAdmin  = "api:admin"
	// block access
	ScopeApiNoAccess = "api:noaccess"
)

Variables

View Source
var (
	// ErrInternalAuthError indicates that soemthing went wrong with the provider
	ErrInternalAuthError = errors.New("internal auth error")
	// ErrInvalidCredentials indicates that the provided credentials did not pass validation
	ErrInvalidCredentials = errors.New("invalid credentials")

	// ErrTokenNotFound indicates that the token is not in the store
	ErrTokenNotFound = errors.New("token not found")

	// ErrNotAuthorized indicates that the API caller is not authorized
	ErrNotAuthorized     = errors.New("not authorized")
	ErrAlreadyAuthorized = errors.New("already authorized")

	// ErrAlreadyInitialized indicates that client is already registered
	ErrAlreadyInitialized = errors.New("already initialized")

	// ErrNoToken indicates that no bearer token was provided
	ErrNoToken = errors.New("no token provided")
	// ErrTokenExpired indicates that the token is no longer valid
	ErrTokenExpired = errors.New("token expired")

	// ErrNoScope indicates that no scope was provided
	ErrNoScope = errors.New("no scope provided")
)

Functions

func CheckAuthorization

func CheckAuthorization(ctx context.Context, c echo.Context, scope string) (*settings.DialSettings, error)

Auth functionallity

CheckAuthorization relies on the presence of a bearer token and validates the matching authorization against a list of requested scopes. If everything checks out, the function returns the authorization or an error otherwise.

func GetBearerToken

func GetBearerToken(r *http.Request) (string, error)

func LookupByToken

func LookupByToken(token string) (*settings.DialSettings, error)

func NewConfig added in v0.3.0

func NewConfig(opts cloudlib.ProviderConfig) (*cloudlib.Provider, error)

func NewDefaultProvider added in v0.3.0

func NewDefaultProvider() interface{}

a default provider with just an in-memory store

func UpdateConfig added in v0.3.0

func UpdateConfig(opts cloudlib.ProviderConfig) (*cloudlib.Provider, error)

func UpdateStore

func UpdateStore(ds *settings.DialSettings) error

Types

type AuthProvider added in v0.3.0

type AuthProvider interface {
	LookupByToken(token string) (*settings.DialSettings, error)
	UpdateStore(ds *settings.DialSettings) error
}

Jump to

Keyboard shortcuts

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