auth

package
v0.0.0-...-4c68550 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoUserSession           = errors.New("no user in session")
	ErrNotAuthenticatedSession = errors.New("not authenticated session")
	ErrNoCsrfTokenInSession    = errors.New("no csrf token in session")
)
View Source
var ErrAccountNotFound = errors.New("account not found")

Functions

func CreateJWTToken

func CreateJWTToken(uuid string, jwtConfig *JwtToken) (string, error)

CreateJWTToken generates a JWT signed token for for the given user

func CreateShigInstanceId

func CreateShigInstanceId(_ string) uuid.UUID

func Csrf

func DeleteSession

func DeleteSession(w http.ResponseWriter, r *http.Request) error

func HttpMiddleware

func HttpMiddleware(ac *SecurityConfig, f http.HandlerFunc) http.HandlerFunc

func SetNewRequestToken

func SetNewRequestToken(w http.ResponseWriter, user string)

func StartSession

func StartSession(w http.ResponseWriter, r *http.Request) error

func TokenMiddleware

func TokenMiddleware(f http.HandlerFunc) http.HandlerFunc

func ValidateSecurityConfig

func ValidateSecurityConfig(config *SecurityConfig) error

Types

type Account

type Account struct {
	User    string        `gorm:"index;unique"`
	UUID    string        `gorm:"index;unique"`
	ActorId uint          `gorm:"not null;unique"`
	Actor   *models.Actor `gorm:"foreignKey:ActorId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	gorm.Model
}

func CreateInstanceAccount

func CreateInstanceAccount(actorId string, actor *models.Actor) *Account

type AccountRepository

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

func NewAccountRepository

func NewAccountRepository(store storage.Storage) *AccountRepository

func (*AccountRepository) Add

func (r *AccountRepository) Add(ctx context.Context, account *Account) (string, error)

type AccountService

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

func NewAccountService

func NewAccountService(repo *AccountRepository, instanceToken string, config *SecurityConfig) *AccountService

func (*AccountService) CreateAccountByActor

func (s *AccountService) CreateAccountByActor(actor *models.Actor) error

func (*AccountService) DeleteAccountByActor

func (s *AccountService) DeleteAccountByActor(actor *models.Actor) error

func (*AccountService) GetAuthToken

func (s *AccountService) GetAuthToken(ctx context.Context, user *authentication.User) (*authentication.Token, error)

type Claims

type Claims struct {
	UUID string `json:"uuid"`
	jwt.RegisteredClaims
}

func (*Claims) GetUuidString

func (c *Claims) GetUuidString() string

type JwtToken

type JwtToken struct {
	Enabled           bool   `mapstructure:"enabled"`
	Key               string `mapstructure:"key"`
	DefaultExpireTime int64  `mapstructure:"defaultexpiretime"`
}

func (JwtToken) KeyFunc

func (jwtToken JwtToken) KeyFunc(token *jwt.Token) (interface{}, error)

KeyFunc auth key types

type Principal

type Principal struct {
	UUID string `json:"uuid"`
}

func GetPrincipalFromSession

func GetPrincipalFromSession(r *http.Request) (*Principal, error)

func PrincipalFromContext

func PrincipalFromContext(ctx context.Context) (Principal, bool)

func ValidateToken

func ValidateToken(tokenString string, jwtConfig *JwtToken) (Principal, error)

func (*Principal) GetUuid

func (principal *Principal) GetUuid() (uuid.UUID, error)

func (*Principal) GetUuidString

func (principal *Principal) GetUuidString() string

type SecurityConfig

type SecurityConfig struct {
	JWT            *JwtToken `mapstructure:"jwt"`
	TrustedOrigins []string  `mapstructure:"trustedOrigins"`
}

Jump to

Keyboard shortcuts

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