authlib

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyUserName      = "uname"
	KeyUserUID       = "uid"
	KeyEmail         = "email"
	KeyRoles         = "roles"
	KeyPermission    = "permission"
	KeyValidUntil    = "validuntil"
	KeyApplicationID = "applicationid"
	KeyToken         = "token"

	UserAuthServiceID = 1
)

Variables

This section is empty.

Functions

func ConvertStringToPrivateKey

func ConvertStringToPrivateKey(privateKey string) *rsa.PrivateKey

func ConvertStringToPublicKey

func ConvertStringToPublicKey(publicKey string) *rsa.PublicKey

func NewBasicAuthenticator

func NewBasicAuthenticator(cfg configlib.Configer, keyProvider KeyProvider) *basicAuthenticator

Types

type ApplicationToken

type ApplicationToken struct {
	ApplicationID    int    `json:"aud"`
	SrcApplicationID int    `json:"iss"`
	UserToken        string `json:"usrt"`
}

type Authenticator

type Authenticator interface {
	GenerateServiceToken(serviceID int) (string, error)
	GenerateServiceTokenWithUserData(serviceID int, ctx context.Context) (string, error)
}

type JWTHeader

type JWTHeader struct {
	Alg string `json:"alg"`
	Typ string `json:"typ"`
}

type JWTPayload

type JWTPayload struct {
	Username   string
	Roles      []string
	Permission map[string]string
	ValidUntil time.Time
}

type KeyProvider

type KeyProvider interface {
	GetPrivateKey() (*rsa.PrivateKey, error)
	GetPublicKey(applicationID int) (*rsa.PublicKey, error)
}

type ObjectPermission

type ObjectPermission map[string]Roles

func (ObjectPermission) HasRoleOn

func (o ObjectPermission) HasRoleOn(object, role string) bool

type Permission

type Permission map[string]ObjectPermission

func (Permission) HasRoleOnOjbectType

func (p Permission) HasRoleOnOjbectType(objectType, object, role string) bool

type Roles

type Roles []string

func (Roles) Has

func (r Roles) Has(role string) bool

type TokenParser

type TokenParser interface {
	ParseUserToken(token string) (UserToken, error)
	ParseApplicationToken(token string) (ApplicationToken, error)
}

type UserToken

type UserToken struct {
	UserName    string     `json:"usr"`
	UserUID     string     `json:"uid"`
	Email       string     `json:"mail"`
	Roles       Roles      `json:"roles"`
	Permissions Permission `json:"permissions"`
	ValidUntil  time.Time  `json:"exp"`
}

Jump to

Keyboard shortcuts

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