auth

package
v0.0.0-...-7412f86 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2015 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidToken error = errors.New("invalid-token")
	ExpiredToken error = errors.New("token-expired")

	ErrNoSignKey   = errors.New("no-sign-key")
	ErrNoVerifyKey = errors.New("no-verify-key")
)
View Source
var (
	ErrNoAuthToken = errors.New("no-auth-token")
)

Functions

func Init

func Init(settings Settings) *serviceImpl

func ReadPublicKey

func ReadPublicKey(filename string) (key []byte, err error)

Types

type CheckScope

type CheckScope func(string, []string) bool

type Context

type Context interface {
	HasKey(key string) bool
	GetString(key string) string
	Get(key string) interface{}
	GetStringForService(service, key string) string
}

type CryptoService

type CryptoService interface {
	Encrypt(key, input []byte) (encrypted []byte, err error)
	Decrypt(key, input []byte) (decrypted []byte, err error)
	EncryptString(input string) (encrypted string, err error)
	HmacSha256(key, input []byte) (h []byte)
	HmacSha256String(key []byte, input string) (h string)
}

type GetScopesFromToken

type GetScopesFromToken func(*Token) []string

type HttpHandler

type HttpHandler func(auth Context, resp http.ResponseWriter, req *http.Request)

type IsAuthOn

type IsAuthOn func() bool

Function to override checking of flag. This is useful for testing to turn off auth.

type Service

type Service interface {
	NewToken() (token *Token)
	SignedStringForHttpRequest(token *Token, req *http.Request) (tokenString string, err error)
	SignedString(token *Token, f SignKey) (tokenString string, err error)
	Parse(tokenString string, f VerifyKey) (token *Token, err error)
	ParseForHttpRequest(tokenString string, req *http.Request) (token *Token, err error)
	RequiresAuth(scope string, get_scopes GetScopesFromToken, handler HttpHandler) func(http.ResponseWriter, *http.Request)
}

type Settings

type Settings struct {
	TTLHours                 time.Duration
	IsAuthOn                 IsAuthOn
	CheckScope               CheckScope
	SignKeyFromHttpRequest   func(*http.Request) []byte
	VerifyKeyFromHttpRequest func(*http.Request) []byte
	ErrorRenderer            func(http.ResponseWriter, *http.Request, string, int) error
	AuthIntercept            func(bool, Context) (bool, Context)
}

Sign keys and verifcation keys are both function of the input which is the http request.

type SignKey

type SignKey func() []byte

type Token

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

func (*Token) Add

func (this *Token) Add(key string, value interface{}) *Token

func (*Token) Get

func (this *Token) Get(key string) interface{}

func (*Token) GetString

func (this *Token) GetString(key string) string

func (*Token) HasKey

func (this *Token) HasKey(key string) bool

func (*Token) SetExpiration

func (this *Token) SetExpiration(d time.Duration)

type UUID

type UUID string

type VerifyKey

type VerifyKey func() []byte

Jump to

Keyboard shortcuts

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