security

package
v0.0.0-...-12912d6 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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

func CorsMiddleware(next http.Handler, frameSource *string) http.Handler

CorsMiddleware enables CORS Request on server (for development purposes)

func ExtractToken

func ExtractToken(r *http.Request) (string, string, string, error)

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

func UserLoginFromContext(ctx context.Context) string

UserLoginFromContext retrieve user login from request context

func ValidateBasicAuthMiddleware

func ValidateBasicAuthMiddleware(next http.Handler, allowedRoles []string) http.Handler

ValidateBasicAuthMiddleware tests if a Basic Auth header is present, and valid, in the request and returns an Error if not

func ValidateJWTMiddleware

func ValidateJWTMiddleware(next http.Handler, allowedRoles []string) http.Handler

ValidateJWTMiddleware tests if a JWT token is present, and valid, in the request and returns an Error if not

func WebSecurityMiddleware

func WebSecurityMiddleware(next http.Handler, frameSource *string) http.Handler

WebSecurityMiddleware adds good practices security headers on http responses

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 ByID

type ByID []User

ByID implements sort.Interface for []User based on the ID field

func (ByID) Len

func (a ByID) Len() int

func (ByID) Less

func (a ByID) Less(i, j int) bool

func (ByID) Swap

func (a ByID) Swap(i, j int)

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 ShareToken

type ShareToken struct {
	CommonClaims
	URL              string `json:"url,omitempty"`              // For share token
	SharingUserLogin string `json:"sharingUserLogin,omitempty"` // For share token
	CanWrite         bool   `json:"canwrite,omitempty"`         // For share token
}

ShareToken represents a token identifying an user

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

func MatchUser

func MatchUser(sentUser User) (User, error)

MatchUser attempt to find the given user against users in configuration file

Jump to

Keyboard shortcuts

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