auth

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated = fmt.Errorf("unauthenticated")
	ErrForbidden       = fmt.Errorf("forbidden")
)

Functions

func GinMiddleware

func GinMiddleware(logger *zap.Logger, jwtService *service_jwt.Service) gin.HandlerFunc

func NewContext

func NewContext(ctx context.Context, s *Subject) context.Context

func RemoveAuthCookie

func RemoveAuthCookie(w http.ResponseWriter)

func SetAuthCookieForUser

func SetAuthCookieForUser(c *gin.Context, userID string, jwtService *service_jwt.Service) error

func UserID

func UserID(ctx context.Context) (string, error)

UserID returns authenticated user's id from the context.

If context if unauthenticated or not user, returns an ErrUnauthenticated.

Types

type Subject

type Subject struct {
	ID   string
	Type SubjectType
}

func FromContext

func FromContext(ctx context.Context) (*Subject, bool)

func SubjectFromGinContext

func SubjectFromGinContext(c *gin.Context) (*Subject, bool)

func SubjectFromRequest

func SubjectFromRequest(r *http.Request, jwtService *service_jwt.Service) (*Subject, error)

type SubjectType

type SubjectType string
const (
	SubjectUndefined SubjectType = ""
	SubjectUser      SubjectType = "user"
	SubjectCI        SubjectType = "ci"
	SubjectMutagen   SubjectType = "mutagen"
	SubjectAnonymous SubjectType = "anonymous"
)

func (SubjectType) String

func (st SubjectType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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