auth

package module
v0.0.0-...-e049142 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2015 License: BSD-3-Clause Imports: 16 Imported by: 1

README

About auth

GoDoc
An authentication, authorization and user management service wrtien in Go

The project provide you 2 ways to use it:

Documentation

Please prefer:

Each sub project may have their own document.

Example

You can find and usage example of the package at https://github.com/kidstuff/auth-example

TODO

  • Fix bugs, improve documentation, more test (not many test right now)
  • Support other type of "grant_type", become an OAuth provider.
  • Better way to handle "permission" (or friendship) becom a social network.
  • A complete example application (a small social network...maybe)

Community

https://groups.google.com/forum/#!forum/kidstuff-opensources
We welcome any feedback, bug report, feature request or just a "Hello" from you!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HANDLER_REGISTER should be "overided" by the "manager". Implement of this function
	// must use the "or" logic for the conditions.
	HANDLER_REGISTER func(fn HandleFunc, owner bool, pri []string) http.Handler
	// DEFAULT_NOTIFICATOR should be "overided" by the "manager".
	DEFAULT_NOTIFICATOR Notificator
	// DEFAULT_LOGGER should be "overided" by the "manager".
	DEFAULT_LOGGER Logger

	OnlineThreshold = time.Hour
	HandleTimeout   = time.Minute * 2
)
View Source
var (
	ErrInvalidCredential = errors.New("kidstuff/auth: Invalid emaill or password")
	ErrInvalidId         = errors.New("kidstuff/auth: Invalif Id")
	ErrInvalidActiveCode = errors.New("kidstuff/auth: Invalid activate code")
	ErrInvalidResetCode  = errors.New("kidstuff/auth: Invalid reset code")
	ErrForbidden         = errors.New("kidstuff/auth: Forbidden")
	ErrPwdMismatch       = errors.New("kidstuff/auth: Pwd and PwdRepeat doesn't match")
	ErrNoKeyProvided     = errors.New("kidstuff/auth: no key provided")
	ErrMailFailed        = errors.New("kidstuff/auth: email send failed")
)

Functions

func Activate

func Activate(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

Activate handle user activation action. If success change user Approved to true. Details: http://kidstuff.github.io/swagger/#!/default/users_user_id_active_get

func AddGroupToUser

func AddGroupToUser(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

AddGroupToUser add group to user. Require "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_user_id_groups_put

func BasicMngrHandler

func BasicMngrHandler(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request, cond *Condition, fn HandleFunc)

BasicMngrHandler can be use in "manager" ServeHTTP after initital required interface like authmodel.UserManager, authmodel.GroupManager, conf.Configurator...etc

func CreateGroup

func CreateGroup(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

CreateGroup document: http://kidstuff.github.io/swagger/#!/default/groups_post

func CreatePasswordResetIssue

func CreatePasswordResetIssue(ctx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

func CreateUser

func CreateUser(ctx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

CreateUser handle create new user accoutn action. Require "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_post

func DeleteUser

func DeleteUser(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

DeleteUser handle delete user account action. Require "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_user_id_delete

func GetToken

func GetToken(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

GetToken handle 'login' action. The token return use to verify later reuqest. Details: http://kidstuff.github.io/swagger/#!/default/tokens_get

func GetUser

func GetUser(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

GetUser return full user account data. Require "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_user_id_get

func JSONError

func JSONError(rw http.ResponseWriter, message string, code int)

JSONError is a helper function to write json error message to http.ResponseWriter

func ListUser

func ListUser(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

ListUser handle user list action. Require "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_get

func RedirectPasswordReset

func RedirectPasswordReset(ctx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

func Serve

func Serve(router *mux.Router)

func SignUp

func SignUp(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

SignUp handle registration action. Details: http://kidstuff.github.io/swagger/#!/default/signup_post

func UpdateApprovedStatus

func UpdateApprovedStatus(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

UpdateApprovedStatus handle user arppoval status update action. Require "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_user_id_approve_put

func UpdateUserProfile

func UpdateUserProfile(authCtx *AuthContext, rw http.ResponseWriter, req *http.Request) (int, error)

UpdateUserProfile handle user's profile update action. Require "owner" or "manage_user" privilege. Details: http://kidstuff.github.io/swagger/#!/default/users_user_id_profile_patch

Types

type AuthContext

type AuthContext struct {
	Auth          authmodel.Manager
	Settings      conf.Configurator
	Notifications Notificator
	Logs          Logger
	// contains filtered or unexported fields
}

func (*AuthContext) ValidCurrentUser

func (ctx *AuthContext) ValidCurrentUser(owner bool, pri []string) (*authmodel.User, error)

ValidCurrentUser validate user privilege and cacuate user total privilege base on groups. In some case a non-nil *authmodel.User object still return with an error.

func (*AuthContext) Value

func (ctx *AuthContext) Value(key interface{}) interface{}

Value returns Gorilla's context package's value for this Context's request and key. It delegates to the parent Context if there is no such value.

type Condition

type Condition struct {
	RequiredPri []string
	Owner       bool
}

type HandleFunc

type HandleFunc func(*AuthContext, http.ResponseWriter, *http.Request) (int, error)

type Logger

type Logger interface {
	// Debugf formats its arguments according to the format, analogous to fmt.Printf,
	// and records the text as a log message at Debug level.
	Debugf(format string, args ...interface{})
	// Infof is like Debugf, but at Info level.
	Infof(format string, args ...interface{})
	// Warningf is like Debugf, but at Warning level.
	Warningf(format string, args ...interface{})
	// Errorf is like Debugf, but at Error level.
	Errorf(format string, args ...interface{})
	// Criticalf is like Debugf, but at Critical level.
	Criticalf(format string, args ...interface{})
}

type Notificator

type Notificator interface {
	SendMail(ctx *AuthContext, subject, message, from, to string) error
}

type SysLogger

type SysLogger struct {
	*syslog.Writer
}

func NewSysLogger

func NewSysLogger(tag string) (*SysLogger, error)

func (*SysLogger) Criticalf

func (l *SysLogger) Criticalf(format string, args ...interface{})

Criticalf is like Debugf, but at Critical level.

func (*SysLogger) Debugf

func (l *SysLogger) Debugf(format string, args ...interface{})

Debugf formats its arguments according to the format, analogous to fmt.Printf, and records the text as a log message at Debug level.

func (*SysLogger) Errorf

func (l *SysLogger) Errorf(format string, args ...interface{})

Errorf is like Debugf, but at Error level.

func (*SysLogger) Infof

func (l *SysLogger) Infof(format string, args ...interface{})

Infof is like Debugf, but at Info level.

func (*SysLogger) Warningf

func (l *SysLogger) Warningf(format string, args ...interface{})

Warningf is like Debugf, but at Warning level.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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