auth

package
v0.0.0-...-a78adbb Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionNotFound = errors.New("session not found")
View Source
var Unauthorized = &SessionClaims{UserID: 0, CreatedAt: time.Unix(0, 0)}

Functions

func DecodeState

func DecodeState(state string, v interface{}) error

func EncodeState

func EncodeState(v interface{}) (string, error)

func SetFingerprintContext

func SetFingerprintContext(ctx echo.Context, fp *Fingerprint)

SetFingerprintContext sets fingerprint (ip, ua, hwid) into http.Request

func SetUserContext

func SetUserContext(ctx echo.Context, user *User)

SetUserContext sets user context into http.Request we need it because gqlgen don't knows about echo.Context and uses http.Request context but there is no easy way to set Request context.

Types

type Auth

type Auth struct {
	*Params
	// contains filtered or unexported fields
}

func New

func New(params Params) (*Auth, error)

New

func (*Auth) InitRoutes

func (a *Auth) InitRoutes(g *echo.Group)

func (*Auth) Middleware

func (a *Auth) Middleware(next echo.HandlerFunc) echo.HandlerFunc

Middleware returns authorization middleware for http server

type Fingerprint

type Fingerprint struct {
	UA   string
	IP   string
	HWID string
}

Fingerprint struct to store data in request context

func ExtractFingerprintContext

func ExtractFingerprintContext(ctx context.Context) *Fingerprint

ExtractFingerprintContext get fingerprint (ip, ua, hwid) from context

type Hook

type Hook struct {
	Id        string            `json:"id"`
	Action    string            `json:"action"`
	UserId    string            `json:"user_id"`
	CreatedAt time.Time         `json:"created_at"`
	Event     map[string]string `json:"event"`
}

type Params

type Params struct {
	fx.In `wire:"-"`

	UserRepo         repository.UserRepository
	UserParamLogRepo repository.UserParamLogRepository
	AuthLog          repository.AuthLogRepository
	Env              *auth.Env
}

type Session

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

func NewSession

func NewSession(env *auth.Session) *Session

New

func (*Session) Drop

func (s *Session) Drop(key string) error

func (*Session) DropAllByExternalID

func (s *Session) DropAllByExternalID(ctx context.Context, externalID string) error

func (*Session) Get

func (s *Session) Get(key string) (*SessionClaims, error)

func (*Session) Set

func (s *Session) Set(key string, claims *SessionClaims) error

type SessionClaims

type SessionClaims struct {
	UserID     int       `json:"user_id,omitempty"`
	ExternalID string    `json:"external_id"`
	CreatedAt  time.Time `json:"created_at"`
	IDToken    string    `json:"id_token"`
}

type State

type State struct {
	Redirect string `json:"redirect"`
	Code     string `json:"code,omitempty"`
}

func (State) MarshalLogObject

func (s State) MarshalLogObject(e zapcore.ObjectEncoder) error

type User

type User struct {
	ID         int
	ExternalID string
	Roles      map[string]bool
}

User struct to store user data in request context

func ExtractUserContext

func ExtractUserContext(ctx context.Context) (*User, bool)

ExtractUserContext get user data from context

func (*User) IsEmpty

func (u *User) IsEmpty() bool

Jump to

Keyboard shortcuts

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