auth

package module
v0.0.0-...-77f9a7e Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 15 Imported by: 0

README

ulms-auth-go

Authentication and authorization library for uLMS Go services.

Build Status

Documentation

Index

Constants

View Source
const (
	ActionCreate = Action("create")
	ActionRead   = Action("read")
	ActionUpdate = Action("update")
	ActionDelete = Action("delete")
)

actions to authorize

Variables

View Source
var ErrorNotAuthorized = fmt.Errorf("not authorized")

ErrorNotAuthorized indicates 403 Forbidden HTTP status code

Functions

func Claims

func Claims(r *http.Request) *jwt.StandardClaims

Claims from request's JWT

func JWT

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

JWT returns request's JWT

Types

type Action

type Action string

Action used to authorize some user's action

type Auth

type Auth interface {
	Issuer(*jwt.StandardClaims) Issuer
	Permission(space string) Permission
	TokenValidationMiddleware() func(next http.Handler) http.Handler
}

Auth is interface containing methods to authenticate and authorize users

func LoadConfiguration

func LoadConfiguration(configFile string, cacheCodec *cache.Codec) (Auth, error)

LoadConfiguration loads current TenantAuth configuration

type Issuer

type Issuer interface {
	Trusted() bool
}

Issuer interface represents issuer interface

type Permission

type Permission interface {
	Check(claims *jwt.StandardClaims, action Action, objectValues ...string) error
	WithContext(ctx context.Context) Permission
}

Permission interface contains methods to check authorization

type TenantAuth

type TenantAuth struct {
	Tenants     map[string]*tenant     `toml:"authn"`
	Permissions map[string]*permission `toml:"authz"`
}

TenantAuth implements Auth interface using tenants

func (*TenantAuth) Issuer

func (auth *TenantAuth) Issuer(claims *jwt.StandardClaims) Issuer

Issuer instance

func (*TenantAuth) Permission

func (auth *TenantAuth) Permission(space string) Permission

Permission instance

func (*TenantAuth) TokenValidationMiddleware

func (auth *TenantAuth) TokenValidationMiddleware() func(next http.Handler) http.Handler

TokenValidationMiddleware returns middleware for validating JWT

Jump to

Keyboard shortcuts

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