auth

package
v0.0.0-...-b7dcdf6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentSession

func CurrentSession(ctx context.Context) *session.Session

CurrentUser returns the user identity from the given context. Nil is returned if no user identity is found in the context.

func Handler

func Handler(verificationKey string, dbase db.IDB, logger log.ILogger, sessRepo session.IRepository) routing.Handler

Handler returns a JWT-based authentication middleware. func Handler(verificationKey string, dbase db.IDB, logger log.ILogger) routing.Handler {

func RegisterHandlers

func RegisterHandlers(rg *routing.RouteGroup, service Service, logger log.ILogger)

RegisterHandlers registers handlers for different HTTP requests.

POST /api/register - регистрация
POST /api/login - логин

Types

type Identity

type Identity interface {
	// GetID returns the user ID.
	GetID() string
	// GetName returns the user name.
	GetName() string
}

Identity represents an authenticated user identity.

type Service

type Service interface {
	// authenticate authenticates a user using username and password.
	// It returns a JWT token if authentication succeeds. Otherwise, an error is returned.
	Login(ctx context.Context, username, password string) (string, error)
	Register(ctx context.Context, username, password string) (string, error)
	NewUser(username, password string) (*user.User, error)
}

Service encapsulates the authentication logic.

func NewService

func NewService(signingKey string, tokenExpiration int, userService user.IService, logger log.ILogger) Service

NewService creates a new authentication service.

type UserService

type UserService interface {
}

Jump to

Keyboard shortcuts

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