auth

package
v0.0.0-...-c511dfe Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: AGPL-3.0 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 AddUser

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

AddUser adds an user

func DeleteUser

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

DeleteUser deletes an user

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 SendUsers

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

SendUsers send users as response from an http requests

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 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           string   `json:"id,omitempty"`
	Login        string   `json:"login"`
	DisplayName  string   `json:"displayName,omitempty"`
	Email        string   `json:"email,omitempty"`
	Roles        []string `json:"memberOf"`
	IsAdmin      bool     `json:"isAdmin,omitempty"`
	Name         string   `json:"name,omitempty"`
	Surname      string   `json:"surname,omitempty"`
	PasswordHash string   `json:"passwordHash,omitempty"`
	Password     string   `json:"password,omitempty"`
}

User represents a logged in 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