auth

package
v0.0.0-...-6f6f875 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ContextData is the user
	ContextData key = 0
)

Variables

View Source
var (
	//UsersFile is the file containing the users
	UsersFile = "./configs/users.json"
)

Functions

func GetShareToken

func GetShareToken(w http.ResponseWriter, r *http.Request)

GetShareToken gets a share token for a given ressource

func ProcessUsers

func ProcessUsers(w http.ResponseWriter, req *http.Request)

ProcessUsers processes users regarding of HTTP method

func ValidateAuthMiddleware

func ValidateAuthMiddleware(next http.Handler, allowedRoles []string, checkXSRF bool) http.Handler

ValidateAuthMiddleware validates that the token is valid and that the user has the correct roles

func WhoAmI

func WhoAmI() http.Handler

WhoAmI returns the user data

Types

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 DataHandler

type DataHandler struct {
	// contains filtered or unexported fields
}

DataHandler has the db connection

func NewDataHandler

func NewDataHandler() *DataHandler

NewDataHandler init a DataHandler and returns a pointer to it

func (*DataHandler) AddUser

func (d *DataHandler) AddUser(w http.ResponseWriter, req *http.Request)

AddUser adds an user

func (*DataHandler) DeleteUser

func (d *DataHandler) DeleteUser(w http.ResponseWriter, req *http.Request)

DeleteUser remove an user

func (*DataHandler) MatchUser

func (d *DataHandler) MatchUser(sentUser User) (User, error)

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

func (*DataHandler) SendUsers

func (d *DataHandler) SendUsers(w http.ResponseWriter, req *http.Request)

SendUsers send users as response from an http requests

func (*DataHandler) UpdateUser

func (d *DataHandler) UpdateUser(w http.ResponseWriter, req *http.Request)

UpdateUser update an user

type Manager

type Manager struct {
	Config      *oauth2.Config
	Hostname    string
	UserInfoURL string
}

Manager exposes the handlers for OAuth2 endpoints

func NewManager

func NewManager() Manager

NewManager returns a new Manager according to environment variables

func (Manager) HandleInMemoryLogin

func (m Manager) HandleInMemoryLogin(w http.ResponseWriter, r *http.Request)

HandleInMemoryLogin validate the username and password provided in the function body against a local file and return a token if the user is found

func (Manager) HandleLogout

func (m Manager) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout remove the user from the cookie store

func (Manager) HandleOAuth2Callback

func (m Manager) HandleOAuth2Callback() http.Handler

HandleOAuth2Callback handles the OAuth2 Callback and get user info

func (Manager) HandleOAuth2Login

func (m Manager) HandleOAuth2Login(w http.ResponseWriter, r *http.Request)

HandleOAuth2Login handles the OAuth2 login

type TokenData

type TokenData struct {
	User
	URL              string `json:"url,omitempty"`
	ReadOnly         bool   `json:"readonly,omitempty"`
	SharingUserLogin string `json:"sharinguserlogin,omitempty"`
	XSRFToken        string `json:"xsrftoken,omitempty"`
}

TokenData represents the data held into a token

func GetTokenData

func GetTokenData(r *http.Request) (TokenData, error)

GetTokenData gets an user from a request

type User

type User struct {
	ID           int    `json:"id,omitempty"`
	IDOAuth      string `json:"idOAuth,omitempry"`
	Login        string `json:"login"`
	DisplayName  string `json:"displayName,omitempty"`
	Role         string `json:"role"`
	IsAdmin      bool   `json:"isAdmin,omitempty"`
	Name         string `json:"name,omitempty"`
	Surname      string `json:"surname,omitempty"`
	PasswordHash string `json:"-"`
	Password     string `json:"password,omitempty"`
}

User represents a logged in user

func GetLoggedUserTechnical

func GetLoggedUserTechnical(w http.ResponseWriter, r *http.Request) User

GetLoggedUserTechnical return the User authenticated

type UserOAuth2

type UserOAuth2 struct {
	ID          string   `json:"id,omitempty"`
	Login       string   `json:"login"`
	DisplayName string   `json:"displayName,omitempty"`
	Groups      []string `json:"memberOf"`
	IsAdmin     bool     `json:"isAdmin,omitempty"`
	Name        string   `json:"name,omitempty"`
	Surname     string   `json:"surname,omitempty"`
}

UserOAuth2 is the user get from OAuth2 authentification

Jump to

Keyboard shortcuts

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