public

package
v0.0.0-...-b2296ca Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JWTWrongSyntax   = errors.New("JWT wrong syntax")
	JWTWrongHead     = errors.New("JWT wrong head")
	JWTWrongAudience = errors.New("This JWT is made for an other audience")
	JWTOutDate       = errors.New("This JWT is out date")
	JWTEmpty         = errors.New("JWT is empty")
)

Functions

This section is empty.

Types

type App

type App struct {
	// The name of the app
	ID string
	// The public key of the auth server
	PublicKey *rsa.PublicKey
	// The name of the cookie who store teh JWT
	// by default it's `auth`
	Cookie string
	// The address of the provider
	Server string
}

The application information. Fill all fields before use it.

func NewApp

func NewApp(id, server string) (*App, error)

Create a new app. id is the the id of the this application in the provider. serv is the url of this provider.

func (*App) Auth

func (a *App) Auth(r string) string

Return the address top the provider to auth. r is teh address to go after autentification work.

func (*App) Login

func (a *App) Login(destination string, h ErrorHandler) http.HandlerFunc

Return a handler for the login. destination is the default destination. h is a handler on error case, if nil it replace by http.Error.

func (*App) Logout

func (a *App) Logout(to string) http.HandlerFunc

Remove the cookie and redirect the client to the variable to; if it's empty, it's set to "/".

func (*App) User

func (a *App) User(r *http.Request) *UserInfo

Get the user from a request cookie. If error occure, the function return nil. If you want the error details, use FromJWT inplace.

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err string, code int)

A variant of http.Error

type Provider

type Provider func(r *http.Request) (*UserInfo, error)

Manage requet from login by a provider

type UserInfo

type UserInfo struct {
	ID     string    `json:"id"`
	Pseudo string    `json:"pseudo"`
	Email  string    `json:"email"`
	Avatar string    `json:"avatar"`
	Level  UserLevel `json:"level"`
}

Public informations, send to web page.

func FromJWT

func FromJWT(j string, pub *rsa.PublicKey, audience string) (*UserInfo, error)

Verify the JWT and parse the JWT.

func (*UserInfo) ToJWT

func (u *UserInfo) ToJWT(priv *rsa.PrivateKey, audience string) (string, error)

ToJWT create a JWT and sign it with pub for a specific audience.

type UserLevel

type UserLevel int
const (
	LevelCandidate UserLevel = iota
	LevelVisitor   UserLevel = iota
	LevelStd       UserLevel = iota
	LevelAdmin     UserLevel = iota
	LevelBan       UserLevel = -1
)

func (UserLevel) MarshalJSON

func (ul UserLevel) MarshalJSON() ([]byte, error)

func (UserLevel) String

func (ul UserLevel) String() string

func (*UserLevel) UnmarshalJSON

func (ul *UserLevel) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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