auth

package
v0.0.0-...-7edcfce Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeUnauthorized          string = "unauthorized"
	ErrorCodeInvalidAuthSchema     string = "invalid_auth_schema"
	ErrorCodeUnsupportedAuthMethod string = "unknown_auth_method"
)
View Source
const AggregationProtocol = "aggregation"
View Source
const NoAuthProtocol = "noauth"

Variables

View Source
var ErrorDescriptions = map[string]string{
	ErrorCodeUnauthorized:          "Request is not authorized.",
	ErrorCodeInvalidAuthSchema:     "Invalid authorization schema.",
	ErrorCodeUnsupportedAuthMethod: "Unsupported authorization method.",
}

Functions

func AuthUserDisplay

func AuthUserDisplay(ctx WithAuthUser) string

func Tenancy

func Tenancy(ctx UserContext) string

Types

type Aggregation

type Aggregation = string
const (
	And Aggregation = "and"
	Or  Aggregation = "or"
)

type Auth

type Auth interface {
	generic_error.ErrorDefinitions
	HandleRequest(ctx AuthContext, path string, access access_control.AccessType) error
}

type AuthBase

type AuthBase struct {
	AuthBaseConfig
	// contains filtered or unexported fields
}

func NewAuth

func NewAuth() *AuthBase

func (*AuthBase) AttachToErrorManager

func (a *AuthBase) AttachToErrorManager(errManager generic_error.ErrorManager)

func (*AuthBase) Config

func (a *AuthBase) Config() interface{}

func (*AuthBase) EndpointsConfig

func (a *AuthBase) EndpointsConfig() EndpointsAuthConfig

func (*AuthBase) HandleRequest

func (a *AuthBase) HandleRequest(ctx AuthContext, path string, access access_control.AccessType) error

func (*AuthBase) Init

func (a *AuthBase) Init(cfg config.Config, log logger.Logger, vld validator.Validator, handlerFactory HandlerFactory, configPath ...string) error

func (*AuthBase) Manager

func (a *AuthBase) Manager() AuthManager

type AuthBaseConfig

type AuthBaseConfig struct {
	DEFAULT_SCHEMA string `default:"check_token"`
}

type AuthContext

type AuthContext interface {
	UserContext
	Session

	GetRequestContent() []byte
	CheckRequestContent(smsMessage *string, skipSms *bool) error
	GetRequestPath() string
	GetRequestMethod() string
	GetResourceId(resourceType string) string
	ResourceIds() map[string]string

	GetRequestClientIp() string
	GetRequestUserAgent() string

	SetAuthParameter(authMethodProtocol string, key string, value string, directKeyName ...bool)
	GetAuthParameter(authMethodProtocol string, key string, directKeyName ...bool) string
}

type AuthDataAccessor

type AuthDataAccessor interface {
	Set(key string, value string)
	Get(key string) string
}

type AuthHandler

type AuthHandler interface {
	common.WithName

	Protocol() string

	Handle(ctx AuthContext) (bool, error)
	Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error
	Handlers() []AuthHandler
	SetAuthManager(manager AuthManager)

	ErrorDescriptions() map[string]string
	ErrorProtocolCodes() map[string]int
}

type AuthHandlerBase

type AuthHandlerBase struct {
	common.WithNameBase
	// contains filtered or unexported fields
}

func (*AuthHandlerBase) ErrorDescriptions

func (a *AuthHandlerBase) ErrorDescriptions() map[string]string

func (*AuthHandlerBase) ErrorProtocolCodes

func (a *AuthHandlerBase) ErrorProtocolCodes() map[string]int

func (*AuthHandlerBase) Handlers

func (a *AuthHandlerBase) Handlers() []AuthHandler

func (*AuthHandlerBase) Init

func (a *AuthHandlerBase) Init(protocol string)

func (*AuthHandlerBase) Protocol

func (a *AuthHandlerBase) Protocol() string

func (*AuthHandlerBase) SetAuthManager

func (a *AuthHandlerBase) SetAuthManager(manager AuthManager)

type AuthManager

type AuthManager interface {
	Handle(ctx AuthContext, schema string) error
	ErrorDescriptions() map[string]string
	ErrorProtocolCodes() map[string]int

	Handlers() HandlerStore
	Schemas() HandlerStore
}

type AuthManagerBase

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

func (*AuthManagerBase) ErrorDescriptions

func (a *AuthManagerBase) ErrorDescriptions() map[string]string

func (*AuthManagerBase) ErrorProtocolCodes

func (a *AuthManagerBase) ErrorProtocolCodes() map[string]int

func (*AuthManagerBase) Handle

func (a *AuthManagerBase) Handle(ctx AuthContext, schema string) error

func (*AuthManagerBase) Handlers

func (a *AuthManagerBase) Handlers() HandlerStore

func (*AuthManagerBase) Init

func (a *AuthManagerBase) Init(cfg config.Config, log logger.Logger, vld validator.Validator, handlerFactory HandlerFactory, configPath ...string) error

func (*AuthManagerBase) Schemas

func (a *AuthManagerBase) Schemas() HandlerStore

type AuthParameterEncryption

type AuthParameterEncryption interface {
	Encrypt(ctx op_context.Context, obj interface{}) (string, error)
	SetAuthParameter(ctx AuthContext, authMethodProtocol string, name string, obj interface{}, directKeyName ...bool) error
	GetAuthParameter(ctx AuthContext, authMethodProtocol string, name string, obj interface{}, directKeyName ...bool) (bool, error)
}

type AuthParameterEncryptionBase

type AuthParameterEncryptionBase struct {
	AuthParameterEncryptionBaseConfig
	Serializer   message.Serializer
	StringCoding utils.StringCoding
}

func (*AuthParameterEncryptionBase) Config

func (a *AuthParameterEncryptionBase) Config() interface{}

func (*AuthParameterEncryptionBase) Encrypt

func (a *AuthParameterEncryptionBase) Encrypt(ctx op_context.Context, obj interface{}) (string, error)

func (*AuthParameterEncryptionBase) GetAuthParameter

func (a *AuthParameterEncryptionBase) GetAuthParameter(ctx AuthContext, authMethodProtocol string, name string, obj interface{}, directKeyName ...bool) (bool, error)

func (*AuthParameterEncryptionBase) Init

func (a *AuthParameterEncryptionBase) Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error

func (*AuthParameterEncryptionBase) SetAuthParameter

func (a *AuthParameterEncryptionBase) SetAuthParameter(ctx AuthContext, authMethodProtocol string, name string, obj interface{}, directKeyName ...bool) error

type AuthParameterEncryptionBaseConfig

type AuthParameterEncryptionBaseConfig struct {
	SECRET            string `validate:"required" mask:"true"`
	PBKDF2_ITERATIONS uint   `default:"256"`
	SALT_SIZE         int    `default:"8" validate:"lte=32,gte=4"`
}

type AuthSchema

type AuthSchema struct {
	AuthHandlerBase
	// contains filtered or unexported fields
}

func NewAuthSchema

func NewAuthSchema() *AuthSchema

func (*AuthSchema) Aggregation

func (a *AuthSchema) Aggregation() Aggregation

func (*AuthSchema) AppendHandlers

func (a *AuthSchema) AppendHandlers(handler ...AuthHandler)

func (*AuthSchema) Config

func (a *AuthSchema) Config() interface{}

func (*AuthSchema) Construct

func (s *AuthSchema) Construct()

func (*AuthSchema) Handle

func (a *AuthSchema) Handle(ctx AuthContext) (bool, error)

func (*AuthSchema) Handlers

func (a *AuthSchema) Handlers() []AuthHandler

func (*AuthSchema) Init

func (a *AuthSchema) Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error

func (*AuthSchema) InitSchema

func (a *AuthSchema) InitSchema(log logger.Logger, cfg config.Config, vld validator.Validator, handlerStore HandlerStore, configPath ...string) error

func (*AuthSchema) Protocol

func (a *AuthSchema) Protocol() string

func (*AuthSchema) SetAggregation

func (a *AuthSchema) SetAggregation(aggregation Aggregation)

type AuthSchemaConfig

type AuthSchemaConfig struct {
	NAME        string `validate:"required"`
	AGGREGATION string `default:"and" validate:"omitempty,oneof=and or"`
}

type ContextWithAuthUser

type ContextWithAuthUser interface {
	op_context.Context
	WithAuthUser
}

type EndpointSchema

type EndpointSchema struct {
	ACCESS      access_control.AccessType
	HTTP_METHOD string
	SCHEMA      string
}

func (*EndpointSchema) Config

func (e *EndpointSchema) Config() interface{}

type EndpointsAuth

type EndpointsAuth interface {
	Auth
	Manager() AuthManager
	EndpointsConfig() EndpointsAuthConfig
}

type EndpointsAuthConfig

type EndpointsAuthConfig interface {
	Schema(path string, accessType access_control.AccessType) (string, bool)
	AddSchema(path string, access access_control.AccessType, schema string)
}

type EndpointsAuthConfigBase

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

func NewEndpointsAuthConfigBase

func NewEndpointsAuthConfigBase() *EndpointsAuthConfigBase

func (*EndpointsAuthConfigBase) AddSchema

func (e *EndpointsAuthConfigBase) AddSchema(path string, access access_control.AccessType, schema string)

func (*EndpointsAuthConfigBase) Init

func (e *EndpointsAuthConfigBase) Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error

func (*EndpointsAuthConfigBase) Schema

type ExpireToken

type ExpireToken struct {
	Exp time.Time `json:"exp"`
}

func (*ExpireToken) Expired

func (e *ExpireToken) Expired() bool

func (*ExpireToken) SetTTL

func (e *ExpireToken) SetTTL(seconds int)

type HandlerFactory

type HandlerFactory interface {
	Create(protocol string) (AuthHandler, error)
}

type HandlerStore

type HandlerStore interface {
	Handler(name string) (AuthHandler, error)
	AddHandler(handler AuthHandler)
	HandlerNames() []string
}

type HandlerStoreBase

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

func NewHandlerStore

func NewHandlerStore() *HandlerStoreBase

func (*HandlerStoreBase) AddHandler

func (h *HandlerStoreBase) AddHandler(handler AuthHandler)

func (*HandlerStoreBase) Handler

func (h *HandlerStoreBase) Handler(name string) (AuthHandler, error)

func (*HandlerStoreBase) HandlerNames

func (h *HandlerStoreBase) HandlerNames() []string

type NoAuth

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

func NewNoAuth

func NewNoAuth() *NoAuth

func (*NoAuth) AttachToErrorManager

func (a *NoAuth) AttachToErrorManager(errManager generic_error.ErrorManager)

func (*NoAuth) HandleRequest

func (a *NoAuth) HandleRequest(ctx AuthContext, path string, access access_control.AccessType) error

type NoAuthMethod

type NoAuthMethod struct {
	AuthHandlerBase
}

func (*NoAuthMethod) Handle

func (n *NoAuthMethod) Handle(ctx AuthContext) (bool, error)

func (*NoAuthMethod) Init

func (n *NoAuthMethod) Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error

func (*NoAuthMethod) SetAuthManager

func (n *NoAuthMethod) SetAuthManager(manager AuthManager)

type Session

type Session interface {
	GetSessionId() string
	SetSessionId(id string)
	GetClientId() string
	SetClientId(id string)
	IsLoggedIn() bool
}

type SessionBase

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

func (*SessionBase) GetClientId

func (u *SessionBase) GetClientId() string

func (*SessionBase) GetSessionId

func (u *SessionBase) GetSessionId() string

func (*SessionBase) IsLoggedIn

func (u *SessionBase) IsLoggedIn() bool

func (*SessionBase) SetClientId

func (u *SessionBase) SetClientId(id string)

func (*SessionBase) SetSessionId

func (u *SessionBase) SetSessionId(id string)

type TenancyUserContext

type TenancyUserContext struct {
	multitenancy.TenancyContextBase
	User User
}

func (*TenancyUserContext) AuthUser

func (u *TenancyUserContext) AuthUser() User

func (*TenancyUserContext) SetAuthUser

func (u *TenancyUserContext) SetAuthUser(user User)

type User

type User interface {
	GetID() string
	Display() string
	Login() string
	IsBlocked() bool
}

type UserBase

type UserBase struct {
	UserId      string `gorm:"index"`
	UserLogin   string `gorm:"index"`
	UserDisplay string `gorm:"index"`
	UserBlocked bool   `gorm:"index"`
}

func NewAuthUser

func NewAuthUser(id string, login string, display string, blocked ...bool) *UserBase

func (*UserBase) Display

func (u *UserBase) Display() string

func (*UserBase) GetID

func (u *UserBase) GetID() string

func (*UserBase) IsBlocked

func (u *UserBase) IsBlocked() bool

func (*UserBase) Login

func (u *UserBase) Login() string

type UserContext

type UserContext interface {
	multitenancy.TenancyContext
	WithAuthUser
}

type UserContextBase

type UserContextBase struct {
	op_context.Context
	User User
}

func NewUserContext

func NewUserContext(fromCtx ...op_context.Context) *UserContextBase

func (*UserContextBase) AuthUser

func (u *UserContextBase) AuthUser() User

func (*UserContextBase) SetAuthUser

func (u *UserContextBase) SetAuthUser(user User)

type WithAuth

type WithAuth interface {
	Auth() Auth
}

type WithAuthBase

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

func (*WithAuthBase) Auth

func (w *WithAuthBase) Auth() Auth

func (*WithAuthBase) Init

func (w *WithAuthBase) Init(auth Auth)

type WithAuthUser

type WithAuthUser interface {
	AuthUser() User
	SetAuthUser(user User)
}

type WithUser

type WithUser interface {
	SetUser(user User)
	GetUserId() string
	GetUserDisplay() string
	GetUserLogin() string
}

type WithUserBase

type WithUserBase struct {
	UserId      string `gorm:"index"`
	UserLogin   string `gorm:"index"`
	UserDisplay string `gorm:"index"`
}

func (*WithUserBase) GetUserDisplay

func (s *WithUserBase) GetUserDisplay() string

func (*WithUserBase) GetUserId

func (s *WithUserBase) GetUserId() string

func (*WithUserBase) GetUserLogin

func (s *WithUserBase) GetUserLogin() string

func (*WithUserBase) SetUser

func (w *WithUserBase) SetUser(user User)

Jump to

Keyboard shortcuts

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