auth

package
v0.0.0-...-51fd5d7 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SessionCookieName = "sess"

Variables

This section is empty.

Functions

func CheckHash

func CheckHash(secret, hash string) bool

CheckHash compare a secret and a hash and return the check result.

func Hash

func Hash(secret string, cost int) (string, error)

Hash returns hashs a secret.

func NewToken

func NewToken(n int) (string, error)

NewToken returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

type APIKeyMeta

type APIKeyMeta struct {
	// Id is the API Key id.
	Id int32
	// UserId is the user identifier.
	UserId int32
	// Role is the user role.
	Role roles.Role
}

func (*APIKeyMeta) Bytes

func (a *APIKeyMeta) Bytes() []byte

type Auth

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

func New

func New(rdb *redis.Client) (*Auth, error)

Creates a new authentication handler

func (*Auth) Close

func (a *Auth) Close() error

func (*Auth) GetRTSPToken

func (a *Auth) GetRTSPToken(ctx context.Context, sess SessionMeta) (token string, err error)

func (*Auth) NewAPIKey

func (a *Auth) NewAPIKey(ctx context.Context, apikey APIKeyMeta, duration time.Duration) (string, error)

Craetes a API key for a user and saves on Redis.

func (*Auth) NewSession

func (a *Auth) NewSession(ctx context.Context, meta SessionMeta) (string, error)

Crates a new session for a user and saves on Redis and remove any old session.

func (*Auth) ReadAPIKeyMetadata

func (a *Auth) ReadAPIKeyMetadata(bytes []byte) (metadata APIKeyMeta, err error)

func (*Auth) ReadSessionMetadata

func (a *Auth) ReadSessionMetadata(bytes []byte) (metadata SessionMeta, err error)

func (*Auth) RemoveAPIKey

func (a *Auth) RemoveAPIKey(ctx context.Context, id int32) error

RemoveAPIKey removes a user API key. If API key doesn't exists returns an error.

func (*Auth) RemoveSession

func (a *Auth) RemoveSession(ctx context.Context, userId int32) error

RemoveSession removes a user session. If session doesn't exists returns an error.

func (*Auth) Validate

func (a *Auth) Validate(ctx context.Context, session string) (metadata SessionMeta, err error)

Validate validates a session on Redis and return the user metadata. An error is returned if fail to comunicate with Redis or session doesn't exist.

func (*Auth) ValidateAPIKey

func (a *Auth) ValidateAPIKey(ctx context.Context, apikey string) (metadata APIKeyMeta, err error)

ValidateAPIKey validates a API key on Redis and return the key metadata. An error is returned if fail to comunicate with Redis or API key doesn't exist.

type AuthConfig

type AuthConfig struct {
}

type SessionMeta

type SessionMeta struct {
	UserId int32
	Role   roles.Role
}

func (*SessionMeta) Bytes

func (m *SessionMeta) Bytes() []byte

Jump to

Keyboard shortcuts

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