Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorResponseDefault(w http.ResponseWriter, _ *http.Request, err error, code int)
- func MarchalJWT(key *rsa.PrivateKey, aud string, u *User) (string, error)
- type App
- type ErrorResponse
- type Handler
- type HandlerFunc
- type Provider
- type Request
- type Teams
- type User
- type UserLevel
Constants ¶
Variables ¶
View Source
var ( ErrNotLogged = errors.New("You are not logged") ErrLowLevel = errors.New("Your level is too low") )
View Source
var ( JWTNeedUserField = errors.New("User need an ID, a Pseudo and an email") JWTEmpty = errors.New("This JWT is empty") JWTOutDate = errors.New("This JWT is out date") JWTWrongAudience = errors.New("This JWT is made for an other audience") JWTWrongHead = errors.New("JWT wrong head") JWTWrongSyntax = errors.New("JWT wrong syntax") JWTWrongSyntaxHead = errors.New("JWT wrong syntax in head") )
View Source
var UserLevelUnknown = errors.New("Unknown UserLevel")
Functions ¶
func ErrorResponseDefault ¶
A simple default ErrorResponse, it's a binding of http.Error.
func MarchalJWT ¶
Create a new JWT to a specific audience.
Types ¶
type App ¶
type App struct { Key *rsa.PublicKey // The public key of the auth provider. Audience string // The audience claim in JWT. Cookie string // JWT cookie name. (by default it's "auth") Error ErrorResponse // Send error response. Mux http.ServeMux // Used direcly to handle no identification request Forget func(u *User) // Forget a user. Can be nil. }
A client app, must be check in the provider. Fill all fields exept Forget.
func (*App) Handle ¶
Wrap the handler with a user level checker: if the level is lower than level, return error and the handler is not call.
func (*App) HandleFunc ¶
type ErrorResponse ¶
Variant of http.Error function.
type Handler ¶
type Handler interface {
ServeHTTP(http.ResponseWriter, *Request)
}
Like http.handler but with a auth.Request.
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *Request)
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *Request)
type Provider ¶
type Provider struct { K *rsa.PrivateKey PEM []byte }
func NewProvier ¶
type Request ¶
type Request struct { http.Request // The User can be nil if the handler UserLevel is set to LevelNo, else it // is never nil. User *User }
An HTTP request with the User. It compose with standard http.Request, so you can access with all method and field simply.
type Teams ¶
The user's teams. To save in JSON, it convert to an array.
func (Teams) MarshalJSON ¶
func (*Teams) UnmarshalJSON ¶
type User ¶
type User struct { ID string `json:"id"` Pseudo string `json:"pseudo"` Email string `json:"email"` Level UserLevel `json:"level"` Bot bool `json:"bot"` Teams Teams `json:"teams"` }
One user
type UserLevel ¶
type UserLevel uint
The user's or bot's accreditation level.
func (UserLevel) MarshalText ¶
func (*UserLevel) UnmarshalText ¶
Click to show internal directories.
Click to hide internal directories.