psw

package
v0.0.0-...-d370aa6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2016 License: MIT Imports: 14 Imported by: 0

README

elsa-auth/psw

GoDoc GoCard

elsa-auth/psw - password authentication for ELSA server applications.

Usage:

s := elsa.NewServer()
s.Handle("/api", elsa.APIServer(s.RPC))

app := auth.NewApp(s.DB)
s.RPC.RegisterService(app, "Auth")
s.Handle("/auth", app) // nginx auth subrequest

Documentation

Overview

Package psw is an API service for password authentication

Index

Constants

View Source
const (
	// Bearer is a prefix of JWT header value
	Bearer = "Bearer"
)

Variables

This section is empty.

Functions

func Config

func Config(c *Flags) func(a *App) error

Config sets config struct

func Cryptor

func Cryptor(a *App) error

Cryptor sets securecookie generator

func Mailer

func Mailer(m *mailer.App) func(a *App) error

Mailer sets mailer

func RandomString

func RandomString(strlen int) string

RandomString returns random string of strlen length with chars from [a-zA-Z0-9]

Types

type Account

type Account struct {
	ID       int64  `xorm:"'id' pk autoincr"`
	Login    string `xorm:"not null unique"`
	Group    string
	Name     string
	Password string
	Email    string `xorm:"not null unique"`
	Phone    string
	Data     string // some account related data
	Disabled bool   `xorm:"not null default 0"`
	Version  int    `xorm:"version"` // Optimistic Locking
}

Account is a user account table

type Accounts

type Accounts []Account

Accounts is an Account slice

type App

type App struct {
	Cryptor  *securecookie.SecureCookie
	DB       *database.DB
	Template *template.Template
	Log      *logger.Log
	Mailer   *mailer.App
	Config   *Flags
}

App - Класс сервера API

func New

func New(db *database.DB, log *logger.Log, options ...func(a *App) error) (a *App, err error)

New - Конструктор сервера API

func (*App) Login

func (a *App) Login(r *http.Request, args *LoginArgs, reply *LoginResp) error

Login - авторизация пользователя

func (*App) ParseJWT

func (a *App) ParseJWT(r *http.Request) (ret *Cookie, err error)

ParseJWT - Расшифровать ключ (TODO: проверить его валидность )

func (*App) Profile

func (a *App) Profile(r *http.Request, args *EmptyArgs, reply *Cookie) error

Profile - return current user's profile (from JWT)

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP - Хэндлер метода /auth

func (*App) UserList

func (a *App) UserList(r *http.Request, args *UserListArgs, reply *Accounts) error

UserList - get user list

func (*App) UserListCount

func (a *App) UserListCount(r *http.Request, args *UserListArgs, reply *RowCount) error

UserListCount - выборка строк из журнала

func (*App) UserSave

func (a *App) UserSave(r *http.Request, args *UserSaveArgs, reply *int64) error

UserSave - add new user

func (*App) UserSendToken

func (a *App) UserSendToken(r *http.Request, args *UserSendTokenArgs, reply *int64) error

UserSendToken - add token by email

func (*App) UserSetPassword

func (a *App) UserSetPassword(r *http.Request, args *UserSetPasswordArgs, reply *int64) error

UserSetPassword - set new password

type Cookie struct {
	Profile
	Stamp time.Time
}

Cookie - структура, которая хранится в JWT

type EmptyArgs

type EmptyArgs struct {
}

EmptyArgs - struct for empty args

type Flags

type Flags struct {
	AppKey    string `long:"psw_session_key" description:"Key to encode user session (default: random key reset on restart)"`
	BlockKey  string `long:"psw_block_key" default:"T<8rYvXmgLBdND(YW}3QRcLwh4$4P5eq" description:"Key to encode session blocks (16,32 or 62 byte)"`
	FailDelay int    `long:"psw_delay" default:"5" description:"Delay response when password wrong (seconds)"`

	AuthHeader string `long:"auth_token_header" default:"X-Elfire-Token" description:"Header field to store auth token"`
	AuthCookie string `long:"auth_token_cookie" default:"elfire_sso_token" description:"Cookie name to store auth token"`
	UIDHeader  string `long:"uid_header" default:"X-Elfire-UID" description:"Header field to store user ID"`
	GIDHeader  string `long:"gid_header" default:"X-Elfire-GID" description:"Header field to store group ID"`

	AdminGroup  string   `long:"adm_group" default:"admin" description:"Admin user group"`
	AdminEmail  string   `long:"adm_email"  default:"ak@elfire.ru" description:"Admin user email"`
	AdminPass   string   `long:"adm_pass"  description:"Admin user password (Default: set random & log)"`
	AdminPrefix []string `long:"adm_prefix"  description:"Prefix of Admin allowed uri"`
	Template    string   `long:"psw_template"  default:"messages.gohtml" description:"Mail templates file"`
}

Flags is a package flags sample in form ready for use with github.com/jessevdk/go-flags

type LoginArgs

type LoginArgs struct {
	Login, Email, Password string
}

LoginArgs - аргументы метода Login

type LoginResp

type LoginResp struct {
	JWT string
}

LoginResp - результат метода Login

type Profile

type Profile struct {
	ID          int64  // User ID
	Name, Group string // User Name and Group
}

Profile - структура профиля

type RowCount

type RowCount int64

RowCount - количество строк в выборке

type TemplateVars

type TemplateVars struct {
	User         Account
	Scheme, Host string
	Meta         map[string]string
	Data         interface{}
}

TemplateVars holds template variables

func (*TemplateVars) SetMeta

func (tv *TemplateVars) SetMeta(key string, values ...string) string

SetMeta used inside templates for metadata setting (like setting email subject)

type UserListArgs

type UserListArgs struct {
	Offset, By, Page int
	Email            string
}

UserListArgs - аргументы метода UserList

type UserSaveArgs

type UserSaveArgs struct {
	ID                              int64
	Notify, Disabled                bool // send email to user
	Login, Name, Email, Group, Data string
}

UserSaveArgs - аргументы метода UserSave

type UserSendTokenArgs

type UserSendTokenArgs struct {
	Email string
}

UserSendTokenArgs - аргументы метода UserSendToken

type UserSetPasswordArgs

type UserSetPasswordArgs struct {
	Password, Password2 string
}

UserSetPasswordArgs - аргументы метода UserSetPassword

Directories

Path Synopsis
api
anon
anon holds anonymous functions
anon holds anonymous functions
mw
acl
jwt
struct

Jump to

Keyboard shortcuts

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