auth

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthAccIDCtxTag         = "auth.accid"
	AuthActiveCharIDCtxTag  = "auth.chrid"
	AuthSubCtxTag           = "auth.sub"
	AuthActiveCharJobCtxTag = "auth.chrjob"
)
View Source
const (
	PermCanBeSuper    = "CanBeSuper"
	PermCanBeSuperKey = "canbesuper"

	PermSuperUser    = "SuperUser"
	PermSuperUserKey = "superuser"

	PermAny = "Any"
)
View Source
const (
	TokenExpireTime  = 96 * time.Hour
	TokenRenewalTime = 48 * time.Hour
	TokenMaxRenews   = 5
)

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 AuthModule = fx.Module("grpc_auth",
	fx.Provide(
		NewGRPCAuth,
	),
)
View Source
var PermsModule = fx.Module("grpc_perms",
	fx.Provide(
		NewGRPCPerms,
	),
)
View Source
var TokenMgrModule = fx.Module("tokenMgr",
	fx.Provide(
		NewTokenMgrFromConfig,
	),
)

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 NewTokenMgrFromConfig added in v0.8.0

func NewTokenMgrFromConfig(cfg *config.Config) *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