auth

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthAccIDCtxTag              = "auth.accid"
	AuthActiveCharIDCtxTag       = "auth.chrid"
	AuthActiveCharJobCtxTag      = "auth.chrjob"
	AuthActiveCharJobGradeCtxTag = "auth.chrjobg"
	AuthSubCtxTag                = "auth.sub"
)
View Source
const (
	PermSuperUser = "SuperUser"
	PermAny       = "Any"
)
View Source
const (
	TokenExpireTime  = 26 * time.Hour
	TokenRenewalTime = 10 * time.Hour
	TokenMaxRenews   = 7
)

Variables

View Source
var (
	ErrNoToken          = status.Errorf(codes.Unauthenticated, "errors.pkg-auth.ErrNoToken")
	ErrInvalidToken     = status.Error(codes.Unauthenticated, "errors.pkg-auth.ErrInvalidToken")
	ErrCheckToken       = status.Error(codes.Unauthenticated, "errors.pkg-auth.ErrCheckToken")
	ErrUserNoPerms      = status.Error(codes.PermissionDenied, "errors.pkg-auth.ErrUserNoPerms")
	ErrNoUserInfo       = status.Error(codes.Unauthenticated, "errors.pkg-auth.ErrNoUserInfo")
	ErrPermissionDenied = status.Errorf(codes.PermissionDenied, "errors.pkg-auth.ErrPermissionDenied")
)
View Source
var UserInfoKey struct{}

Functions

func FromContext

func FromContext(ctx context.Context) (*userinfo.UserInfo, bool)

func GetTokenFromGRPCContext

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

func GetUserInfoFromContext

func GetUserInfoFromContext(ctx context.Context) (*userinfo.UserInfo, bool)

func MustGetUserInfoFromContext

func MustGetUserInfoFromContext(ctx context.Context) *userinfo.UserInfo

func SetTokenClaimsTimes

func SetTokenClaimsTimes(claims *CitizenInfoClaims)

Types

type CitizenInfoClaims

type CitizenInfoClaims struct {
	AccID        uint64 `json:"accid"`
	Username     string `json:"usr"`
	CharID       int32  `json:"chrid"`
	RenewedCount int32  `json:"renwc"`

	jwt.RegisteredClaims
}

func BuildTokenClaimsFromAccount

func BuildTokenClaimsFromAccount(account *model.FivenetAccounts, activeChar *users.User) *CitizenInfoClaims

type GRPCAuth

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

func NewGRPCAuth

func NewGRPCAuth(ui userinfo.UserInfoRetriever, tm *TokenMgr) *GRPCAuth

func (*GRPCAuth) GRPCAuthFunc

func (g *GRPCAuth) GRPCAuthFunc(ctx context.Context, fullMethod string) (context.Context, error)

func (*GRPCAuth) GRPCAuthFuncWithoutUserInfo

func (g *GRPCAuth) GRPCAuthFuncWithoutUserInfo(ctx context.Context, fullMethod string) (context.Context, error)

type GRPCPerm

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

func NewGRPCPerms

func NewGRPCPerms(p perms.Permissions) *GRPCPerm

func (*GRPCPerm) GRPCPermissionStreamFunc

func (g *GRPCPerm) GRPCPermissionStreamFunc(ctx context.Context, srv interface{}, info *grpc.StreamServerInfo) (context.Context, error)

func (*GRPCPerm) GRPCPermissionUnaryFunc

func (g *GRPCPerm) GRPCPermissionUnaryFunc(ctx context.Context, info *grpc.UnaryServerInfo) (context.Context, error)

type TokenMgr

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

func NewTokenMgr

func NewTokenMgr(jwtSecret string) *TokenMgr

func (*TokenMgr) NewWithClaims

func (t *TokenMgr) NewWithClaims(claims *CitizenInfoClaims) (string, error)

func (*TokenMgr) ParseWithClaims

func (t *TokenMgr) ParseWithClaims(tokenString string) (*CitizenInfoClaims, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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