authentication

package
v0.0.0-...-e319382 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 21 Imported by: 12

Documentation

Index

Constants

View Source
const JWTToken = "jwtToken"

JWTToken constant

Variables

View Source
var (
	// Roles contains the roles for the active auth driver
	Roles []Role
)

Functions

func DeleteCookies

func DeleteCookies(w http.ResponseWriter)

DeleteCookies invalidate the JWT and XSTF cookies

func GetJWTFromContext

func GetJWTFromContext(r *http.Request) *jwt.Token

GetJWTFromContext retrieves the JWT Token from the request

func GetToken

func GetToken(user *User, xsfrToken string) (string, error)

GetToken returns a string that contain the token

func SetCookies

func SetCookies(w http.ResponseWriter, r *http.Request, authenticationToken, xsrfToken string)

SetCookies set the proper cookies for the JWT and XSFR tokens

Types

type Config

type Config struct {
	Auth       structs.Auth
	DriverFn   loginFn
	DriverName string
}

Config contains the authentication configuration

func New

func New(auth structs.Auth) Config

New function initalizes and returns a Config struct

func (*Config) Advanced

func (a *Config) Advanced(driver loginFn, driverName string)

Advanced function allows a third party Identification driver

func (*Config) Authenticate

func (c *Config) Authenticate(next http.Handler) http.Handler

Authenticate calls the proper handler based on whether authentication is enabled or not

func (*Config) Login

func (c *Config) Login() http.Handler

Login authenticates a user against the authentication driver

func (*Config) None

func (a *Config) None()

None function sets the Config struct in order to disable authentication

func (*Config) Simple

func (a *Config) Simple(u []User)

Simple function sets the Config struct in order to enable simple authentication based on provided user and pass

type Methods

type Methods struct {
	Delete []string
	Head   []string
	Get    []string
	Post   []string
}

Methods contains the allowed endpoints for each HTTP method

type Role

type Role struct {
	AccessToken   string
	Datacenters   []string
	Fallback      bool
	Members       []string
	Methods       Methods
	Name          string
	Readonly      bool
	Subscriptions []string
}

Role contains the attributes of a role

func GetRoleFromToken

func GetRoleFromToken(token *jwt.Token) (*Role, error)

GetRoleFromToken ...

type TokenLocation

type TokenLocation func(r *http.Request) (string, error)

TokenLocation represents a function that accepts a request as input and returns either a token or an error.

type User

type User struct {
	ID           int64
	AccessToken  string
	Email        string
	FullName     string
	Password     string
	PasswordHash string
	PasswordSalt string
	Readonly     bool
	Role         Role
	Token        string
	Username     string
}

User contains the attributes of a user

Jump to

Keyboard shortcuts

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