Documentation
¶
Index ¶
- Variables
- type App
- func (a *App) Call(w http.ResponseWriter, r *http.Request, level UserLevel, handler Handler)
- func (a *App) CallFunc(w http.ResponseWriter, r *http.Request, level UserLevel, ...)
- func (a *App) FromJWT(j string) (*UserInfo, error)
- func (a *App) Handle(pattern string, level UserLevel, handler Handler)
- func (a *App) HandleFunc(p string, l UserLevel, f func(w http.ResponseWriter, r *Request))
- func (a *App) Login(destination string) http.HandlerFunc
- func (a *App) Logout(to string) http.HandlerFunc
- func (a *App) ProviderAuth(r string) string
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) User(r *http.Request) *UserInfo
- type ExternProvider
- type HandleFunc
- type Handler
- type Provider
- type Request
- type UserInfo
- type UserLevel
Constants ¶
This section is empty.
Variables ¶
var ( JWTWrongSyntax = errors.New("JWT wrong syntax") JWTWrongSyntaxHead = errors.New("JWT wrong syntax in head") 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 address of the provider
Provider string
// The public key of the auth provider
PublicKey *rsa.PublicKey
// The audience field in JWT.
Audience string
// The name of the cookie who store the JWT
// by default it's `auth`
Cookie string
//
Mux http.ServeMux
// A variant of http.Error used to send the error to the client. By default
// its a binding of http.Error.
Error func(w http.ResponseWriter, r *http.Request, err string, code int)
}
The application information. Fill all fields before use it.
func NewApp ¶
Create a new app. id is the the id of the this application in the provider. provider is the url of this provider.
defaultHandler registers the handler for login and logout
func (*App) Call ¶
Call handler if the user who make the request has a enought level. If the level is less than LevelCandidate, the user can be nil.
func (*App) CallFunc ¶
func (a *App) CallFunc(w http.ResponseWriter, r *http.Request, level UserLevel, f func(w http.ResponseWriter, r *Request))
Like App.Call but for a func(w http.ResponseWriter, r *Request)
func (*App) Handle ¶
Add a handler to a.Mux. The level of the user must be over level.
If the level is strict strict less than LevelCandidate, the user can be nil or with a lower level.
func (*App) HandleFunc ¶
Like App.Handle with a function inplace of a Handler.
func (*App) Login ¶
func (a *App) Login(destination string) http.HandlerFunc
Return a handler for the login. This handler takes the jwt from the URL and save it a cookie. Finaly it redirect the client to the params r or destination.
func (*App) Logout ¶
func (a *App) Logout(to string) http.HandlerFunc
Remove the cookie and redirect the client to the variable to (or "/" if empty)
func (*App) ProviderAuth ¶
Return the address top the provider to auth. r is the address to go after autentification work.
type ExternProvider ¶
Manage request from login by a provider
type HandleFunc ¶
type HandleFunc func(w http.ResponseWriter, r *Request)
HandleFunc with Request inplace of http.Request
func (HandleFunc) ServeHTTP ¶
func (f HandleFunc) ServeHTTP(w http.ResponseWriter, r *Request)
type Handler ¶
type Handler interface {
ServeHTTP(http.ResponseWriter, *Request)
}
HTTP.Handler with the custom request
type Provider ¶
type Provider struct {
PrivKey *rsa.PrivateKey
Pub []byte // the PEM public key encoded
}
The information about the providers,
func NewProvider ¶
Create a new app. id is the the id of the this application in the provider. serv is the url of this 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.
type UserLevel ¶
type UserLevel int