c8yauth

package
v0.0.0-...-29f2d0a Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecurityContextKey = "__SecurityContextKey__"
)

Variables

This section is empty.

Functions

func AuthenticationBasic

func AuthenticationBasic(authProvider *AuthenticationProvider) echo.MiddlewareFunc

func AuthenticationBearer

func AuthenticationBearer(authProvider *AuthenticationProvider) echo.MiddlewareFunc

func Authorization

func Authorization(roles ...Role) echo.MiddlewareFunc

Authorization checks if context contains at least one given privilege (OR check) on failure request ends with 401 unauthorized error

func NewBasicAuthorizationContext

func NewBasicAuthorizationContext(tenant, username, password string) context.Context

func NewBearerAuthorizationContext

func NewBearerAuthorizationContext(token string) context.Context

func SkipCheck

func SkipCheck(c echo.Context) bool

Types

type AuthContext

type AuthContext struct {
	UserID string
	Tenant string
	Roles  map[string]struct{}
}

AuthContext holds information about user who has been authenticated for request

func GetUserSecurityContext

func GetUserSecurityContext(c echo.Context) (AuthContext, error)

func (*AuthContext) CheckPrivilege

func (s *AuthContext) CheckPrivilege(roles ...Role) bool

CheckPrivilege checks if user in AuthContext has at least one (OR) of given privilege

type AuthenticationProvider

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

func NewAuthProvider

func NewAuthProvider(client *c8y.Client) *AuthenticationProvider

func (*AuthenticationProvider) Authorize

func (a *AuthenticationProvider) Authorize(ctx context.Context) (AuthContext, bool)

type ErrInvalidAuthType

type ErrInvalidAuthType struct {
	Err error
}

ErrInvalidAuthType is error type when the KeyAuth middleware detects and invalid auth type, e.g. Basic vs Bearer

func (*ErrInvalidAuthType) Error

func (e *ErrInvalidAuthType) Error() string

Error returns errors text

type Role

type Role string
const (
	RoleTokenRead   Role = "ROLE_TOKEN_TRIAL_REQUEST_READ"
	RoleTokenCreate Role = "ROLE_TOKEN_TRIAL_REQUEST_CREATE"
	RoleTokenAdmin  Role = "ROLE_TOKEN_TRIAL_REQUEST_ADMIN"
)

Jump to

Keyboard shortcuts

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