auth

package
v0.0.0-...-fdf5f90 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NIL                        Permission = 0
	SIGN_OUT                              = 1 << iota
	GRANT_SUPER                           = 1 << iota
	REVOKE_SUPER                          = 1 << iota
	NEEDLE_FOR_NEXT_PERMISSION            = iota

	BASIC_EMAIL AuthType = iota - NEEDLE_FOR_NEXT_PERMISSION
)

Variables

View Source
var Permissions = map[string]Permission{
	"create_bloq":    CREATE_BLOQ,
	"update_bloq":    UPDATE_BLOQ,
	"delete_bloq":    DELETE_BLOQ,
	"create_offer":   CREATE_OFFER,
	"update_offer":   UPDATE_OFFER,
	"delete_offer":   DELETE_OFFER,
	"create_order":   CREATE_ORDER,
	"delete_order":   DELETE_ORDER,
	"create_profile": CREATE_PROFILE,
	"read_profile":   CREATE_PROFILE,
	"update_profile": UPDATE_PROFILE,
	"delete_profile": DELETE_PROFILE,
	"default":        DEFAULT_PERMISSIONS,
}
View Source
var SuperPermissions = map[string]Permission{
	"create_preference": CREATE_PREFERENCE,
	"update_preference": UPDATE_PREFERENCE,
	"delete_preference": DELETE_PREFERENCE,
}

Functions

func CredentialsToID

func CredentialsToID(c *proto.Credentials) *string

func ErrorToValidation

func ErrorToValidation(err error, status *uint32) *proto.Validation

func GetPermissionsHash

func GetPermissionsHash(p Permission) string

func GetPermissionsList

func GetPermissionsList(super bool) map[string]Permission

func Invalid

func Invalid(msg string, status *uint32) *proto.Validation

func IsAuthMethodSupported

func IsAuthMethodSupported(s string) bool

func Valid

func Valid(msg string, status *uint32) *proto.Validation

Types

type AuthClient

type AuthClient struct {
}

func (*AuthClient) Validate

func (s *AuthClient) Validate(ctx context.Context, in *proto.Token) (*proto.Validation, error)

type AuthServer

type AuthServer struct {
	proto.UnimplementedAuthServer
	// contains filtered or unexported fields
}

func NewAuthServer

func NewAuthServer(a Auther, t Tokener) *AuthServer

func (*AuthServer) IsSuper

func (s *AuthServer) IsSuper(ctx context.Context, in *proto.Credentials) (v *proto.Validation, err error)

func (*AuthServer) LogIn

func (*AuthServer) LogOut

func (s *AuthServer) LogOut(ctx context.Context, in *proto.Token) (*proto.Validation, error)

func (*AuthServer) SignIn

func (s *AuthServer) SignIn(ctx context.Context, in *proto.Credentials) (*proto.Validation, error)

func (*AuthServer) SignOut

func (s *AuthServer) SignOut(ctx context.Context, in *proto.Token) (*proto.Validation, error)

func (*AuthServer) Validate

func (s *AuthServer) Validate(ctx context.Context, in *proto.Token) (*proto.Validation, error)

type AuthType

type AuthType uint8

type Auther

type Claims

type Claims struct {
	Payload
	jwt.RegisteredClaims
}

type NoPermissionsError

type NoPermissionsError struct {
	Permission Permission
}

func (NoPermissionsError) Error

func (err NoPermissionsError) Error() string

type Payload

type Payload struct {
	Client      string     `json:"client"`
	Permissions Permission `json:"permissions"`
	Super       bool       `json:"is_super"`
	Type        AuthType   `json:"type"`
}

type Permission

type Permission uint64
const (
	CREATE_PREFERENCE Permission = 1 << (NEEDLE_FOR_NEXT_PERMISSION + iota)
	UPDATE_PREFERENCE
	DELETE_PREFERENCE

	CREATE_PROFILE
	READ_PROFILE
	UPDATE_PROFILE
	DELETE_PROFILE

	CREATE_BLOQ
	UPDATE_BLOQ
	DELETE_BLOQ

	CREATE_OFFER
	UPDATE_OFFER
	DELETE_OFFER

	CREATE_ORDER
	DELETE_ORDER

	PREFERENCE_MANAGER = CREATE_PREFERENCE | UPDATE_PREFERENCE | DELETE_PREFERENCE

	DEFAULT_PERMISSIONS = CREATE_PROFILE |
		READ_PROFILE |
		CREATE_BLOQ |
		UPDATE_BLOQ |
		CREATE_OFFER |
		CREATE_ORDER |
		DELETE_ORDER
)

type Token

type Token string

type Tokener

type Tokener interface {
	GenToken(context.Context, *Payload) (Token, error)
	VerifyToken(context.Context, Token, Permission) (bool, error)
	RevokeToken(context.Context, Token) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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