auth

package
v0.0.0-...-430e8a6 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatProvider

func FormatProvider(provider string) string

FormatProvider formats a provider string from a request to the DB and issuer format

func GetUser

func GetUser(w http.ResponseWriter) user.User

GetUser gets a domain user from a hydrated userContext will return an empty domain user if not found

func HRAuthorize

func HRAuthorize(perm Permission, userRequired bool, l Logger, f Formatter, next httprouter.Handle) httprouter.Handle

HRAuthorize wraps authorization logic in httprouter middleware

func HRHydrateUser

func HRHydrateUser(userRepo usecase.UserRepo, l Logger, f Formatter, required bool, next httprouter.Handle) httprouter.Handle

HRHydrateUser wraps HydrateUser in httprouter middleware

func HydrateUser

func HydrateUser(userRepo usecase.UserRepo, l Logger, f Formatter, required bool, next http.Handler) http.Handler

HydrateUser middleware hydrates a UserContext with a user will respond with a 401 unauthorized response if required is set to true and no user could be found

Types

type Auth

type Auth struct {
	Authenticator
	// contains filtered or unexported fields
}

Auth base struct for auth implementations

func New

func New(l Logger) *Auth

New creates a new base Auth struct (useful for test stubbing)

func (*Auth) Authenticate

func (a *Auth) Authenticate(next http.Handler) http.Handler

Authenticate stub authentication method

func (*Auth) SetFormatter

func (a *Auth) SetFormatter(f Formatter)

SetFormatter sets the formatter on the Auth struct

type Auth0

type Auth0 struct {
	Auth
	// contains filtered or unexported fields
}

Auth0 contains dependencies for the Auth0 handler

func NewAuth0

func NewAuth0(l Logger, c Auth0Config) *Auth0

NewAuth0 returns a new Auth struct

func (*Auth0) Authenticate

func (a *Auth0) Authenticate(next http.Handler) http.Handler

Authenticate authenticates a request and calls the next handler

type Auth0Config

type Auth0Config struct {
	Secret   []byte
	Audience []string
	Domain   string
}

Auth0Config contains configuration options for Auth0 handler

type Authenticator

type Authenticator interface {
	SetFormatter(f Formatter)
	Authenticate(next http.Handler) http.Handler
}

Authenticator interface for authorization

type Context

type Context struct {
	Issuer      string
	Subject     string
	Permissions []Permission
}

Context contains relevant auth data from request

func (*Context) HasPerm

func (c *Context) HasPerm(permission Permission) bool

HasPerm returns true if the request token has the specified permission

type Formatter

type Formatter interface {
	WriteResponse(w http.ResponseWriter, res []byte, statusCode int)
	ErrUnauthorized(w http.ResponseWriter)
	Error(a interface{}) []byte
}

Formatter defines the formatter interface for output responses

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger interface needed for log messages

type Permission

type Permission int64

Permission type

const (
	PermNone           Permission = 0
	PermUpsertUserSelf Permission = 1 << iota
	PermUpsertTask     Permission = 1 << iota
	PermReadTask       Permission = 1 << iota
	PermDeleteTask     Permission = 1 << iota
	PermUpsertSchedule Permission = 1 << iota
	PermReadSchedule   Permission = 1 << iota
	PermDeleteSchedule Permission = 1 << iota
)

Application permissions, string must match exactly what is sent in access tokens from auth provider

func GetAnonymousUserPerms

func GetAnonymousUserPerms() []Permission

GetAnonymousUserPerms returns the permissions needed for the anonymous app user

func GetDefaultUserPerms

func GetDefaultUserPerms() []Permission

GetDefaultUserPerms returns the default list of permissions for a standard app user

func (Permission) String

func (p Permission) String() string

type ResponseContext

type ResponseContext struct {
	http.ResponseWriter
	Auth Context
}

ResponseContext wraps http.ResponseWriter in a context that provides authorization details to other handlers

type UserContext

type UserContext struct {
	http.ResponseWriter
	User *user.User
	Auth Context
}

UserContext wraps http.ResponseWriter in a context that provides a hydrated domain user to other handlers

Jump to

Keyboard shortcuts

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