Documentation ¶
Index ¶
- Constants
- func Authenticate(w http.ResponseWriter, req *http.Request)
- func CorsMiddleware(next http.Handler, frameSource *string) http.Handler
- func ExtractToken(r *http.Request) (string, string, string, error)
- func GetShareToken(w http.ResponseWriter, req *http.Request)
- func SendUsers(w http.ResponseWriter, req *http.Request)
- func SetUsers(w http.ResponseWriter, req *http.Request)
- func UserLoginFromContext(ctx context.Context) string
- func ValidateBasicAuthMiddleware(next http.Handler, allowedRoles []string) http.Handler
- func ValidateJWTMiddleware(next http.Handler, allowedRoles []string) http.Handler
- func WebSecurityMiddleware(next http.Handler, frameSource *string) http.Handler
- type AuthToken
- type AuthenticationMiddleware
- type ByID
- type CommonClaims
- type ShareToken
- type User
Constants ¶
const ( // ContextLogin is the connected user login from the request context ContextLogin key = 0 // ContextRole is the connected user role from the request context ContextRole key = 1 )
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
func Authenticate(w http.ResponseWriter, req *http.Request)
Authenticate validate the username and password provided in the function body against a local file and return a token if the user is found
func CorsMiddleware ¶
CorsMiddleware enables CORS Request on server (for development purposes)
func ExtractToken ¶
ExtractToken from a cookie OR an authorization header in the form `Bearer <JWT Token>` OR a URL query paramter of the form https://example.com?token=<JWT token> returns the token, a string indicating the token type, a string indicating where the token comes from, and an error
func GetShareToken ¶
func GetShareToken(w http.ResponseWriter, req *http.Request)
GetShareToken provide a token to access the ressource on a given url
func SendUsers ¶
func SendUsers(w http.ResponseWriter, req *http.Request)
SendUsers send users as response from an http requests
func SetUsers ¶
func SetUsers(w http.ResponseWriter, req *http.Request)
SetUsers sets users from an http request
func UserLoginFromContext ¶
UserLoginFromContext retrieve user login from request context
func ValidateBasicAuthMiddleware ¶
ValidateBasicAuthMiddleware tests if a Basic Auth header is present, and valid, in the request and returns an Error if not
func ValidateJWTMiddleware ¶
ValidateJWTMiddleware tests if a JWT token is present, and valid, in the request and returns an Error if not
Types ¶
type AuthToken ¶
type AuthToken struct { CommonClaims CSRFToken string `json:"csrftoken"` }
AuthToken represents a token identifying an user
type AuthenticationMiddleware ¶
type AuthenticationMiddleware struct {
AllowedRoles []string
}
AuthenticationMiddleware allow access for users of allowed Roles
func (*AuthenticationMiddleware) ValidateJWTMiddleware ¶
func (amw *AuthenticationMiddleware) ValidateJWTMiddleware(next http.Handler) http.Handler
ValidateJWTMiddleware tests if a JWT token is present, and valid, in the request and returns an Error if not
type CommonClaims ¶
type CommonClaims struct { Login string `json:"login"` Role string `json:"role"` jwt.StandardClaims }
CommonClaims represents the claims common to Auth and Share tokens
type User ¶
type User struct { ID int `json:"id"` Login string `json:"login"` Name string `json:"name"` Surname string `json:"surname"` Role string `json:"role"` PasswordHash string `json:"passwordHash"` Password string `json:"password,omitempty"` LongLivedToken bool `json:"longLivedToken"` }
User represents an application user