apptokens

package
v0.0.0-...-a67b36e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingFields      = fmt.Errorf("AppToken must have appRefUuid/hash/owner")
	ErrWrongAppHash       = fmt.Errorf("provided org/app-name hash does not match with db record")
	ErrAppTokenStillValid = fmt.Errorf("current AppToken is still valid")
	ErrNoReadWriteAccess  = fmt.Errorf("user read/write access for AppToken")
	ErrNoReadAccess       = fmt.Errorf("user has no read access for AppToken")
)

Functions

func ClaimsFromJwt

func ClaimsFromJwt(jwtString string) (string, string, int, error)

func IsCorrupted

func IsCorrupted(jwtString string) (string, string, int, error)

TODO: needs to check refresh count IsCorrupted checks if the Json-Web-Token it self is valid and be decoded using the secure further more it checks if the token has been expired

Types

type AppToken

type AppToken struct {
	AppRefUuid   string   `bson:"_id" required:"yes"`
	OwnerOrgn    string   `bson:"owner_orgn"`
	Locked       bool     `bson:"locked"`
	IsPrivate    bool     `bson:"is_private"`
	AppHash      string   `bson:"app_hash" required:"yes"`
	AppOwner     string   `bson:"app_owner" required:"yes"`
	AppOrigin    string   `bson:"app_origin"`
	Member       []string `bson:"member"`
	Jwt          string   `bson:"app_jwt"`
	Exp          int64    `bson:"app_jwt_exp"`
	RefreshCount int32    `bson:"refresh_count"`
}

AppToken represents the token data as it will be stored in the datbase

func NewDefault

func NewDefault(AppRefUuid, appHash, appOwner, ownerOrgn, appOrigin string, isPrivate bool) (*AppToken, error)

NewDefault creates a new default AppToken with only the meta data but no valid Jwt nor Expiration time

func (*AppToken) AddMember

func (appToken *AppToken) AddMember(userUuid string)

func (AppToken) CompareHash

func (appToken AppToken) CompareHash(orgn, appName string) bool

CompareHash compares if the provided meta data (orgnanization name and app name) match with the apptoken.Hash.

func (AppToken) HasRead

func (appToken AppToken) HasRead(userUuid string, userOrgn string) error

HasRead checks if the user has read access on the AppToken

func (AppToken) HasReadOrWrite

func (appToken AppToken) HasReadOrWrite(userUuid string, userOrgn string) error

HasReadOrWrite checks if the user has either read or write acces on the AppToken

func (AppToken) HasReadWrite

func (appToken AppToken) HasReadWrite(userUuid string) error

HasReadWrite checks if the provided user uuid is listed as owner of AppToken

func (AppToken) IsValid

func (appToken AppToken) IsValid(jwtRefreshCount int) bool

IsValid matches the JWT refresh count with the refresh count from the database if they dont match, the app-token is marked as invalid

func (*AppToken) Issue

func (appToken *AppToken) Issue(orgn, appName string) (*AppToken, error)

Issue issues a new AppToken with an updated Jwt and Exp and RefreshCount. The operation fails if the current AppToken.Exp has not yet expired

func (AppToken) JWT

func (appToken AppToken) JWT() (string, int64, error)

JWT creates a new JSON-Web-Token based on the current AppToken information

func (AppToken) MarkDirty

func (appToken AppToken) MarkDirty() *AppToken

MarkDirty updates the refresh count of an app token invalidating the all other app tokens it will unset the jwt, ext

type ApptokenRepo

type ApptokenRepo interface {
	Initialize(ctx context.Context, appToken AppToken) error
	GetById(ctx context.Context, uuid string, result interface{}) error
	Update(ctx context.Context, uuid, jwt string, exp int64, refreshCount int32) error
	SetAppTokenLock(ctx context.Context, uuid string, lock bool) error

	AddMember(ctx context.Context, uuid, userUuid string) error
	RollbackAddMember(ctx context.Context, uuid, userUuid string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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