auth

package
v0.0.0-...-aec784a Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package auth provides ability to verify API Keys, that brings an abstraction layer between applications that require API Key authentication and authentication providers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCouldNotOpenKeyStore  = errors.New("ErrCouldNotOpenKeyStore")
	ErrCouldNotCloseKeyStore = errors.New("ErrCouldNotCloseKeyStore")
	ErrCouldNotAuthenticate  = errors.New("ErrCouldNotAuthenticate")
	ErrCouldNotDeleteKey     = errors.New("ErrCouldNotDeleteKey")
	ErrKeyNotFound           = errors.New("ErrKeyNotFound")
	ErrCouldNotGenerateKey   = errors.New("ErrCouldNotGenerateKey")
)

Errors

View Source
var NextKeyFn = UUIDNextKey

NextKeyFn generates next key and is used by DocstoreAuth. Default is UUID Version 4.

Functions

func UUIDNextKey

func UUIDNextKey() string

UUIDNextKey returns an UUID Version 4, without hyphens.

Types

type APIKey

type APIKey struct {
	Key                 string `docstore:"key"`
	ScopeRegisterAll    bool   `docstore:"scope_register_all"`    // globalAdmin: You can do whatever you want.
	ScopeRegisterDomain bool   `docstore:"scope_register_domain"` // domainAdmin: DomainID will be checked.
	DomainID            string `docstore:"domid"`
	Note                string `docstore:"note"`
}

APIKey contains API key and scope.

type Authenticator

type Authenticator interface {
	AuthFunc(ctx context.Context, apiKey string, params map[string]string) bool
	io.Closer
}

type DocstoreAuth

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

DocstoreAuth provides AuthFunc and is backed by docstore.

func MustNewDocstoreAuth

func MustNewDocstoreAuth(conn string) *DocstoreAuth

MustNewDocstoreAuth initializes an DocstoreAuth, panics if failed to access datastore.

func (*DocstoreAuth) AuthFunc

func (a *DocstoreAuth) AuthFunc(ctx context.Context, apiKey string, params map[string]string) bool

AuthFunc handles authentication.

func (*DocstoreAuth) Close

func (a *DocstoreAuth) Close() error

Close closes the DocstoreAuth.

func (*DocstoreAuth) Delete

func (a *DocstoreAuth) Delete(ctx context.Context, apiKey string) error

Delete deletes the APIKey specified by apiKey from datastore. No errors returned when the APIKey does not exist.

func (*DocstoreAuth) Do

func (a *DocstoreAuth) Do(ctx context.Context, apiKey string, domainID string) (bool, error)

Do authenticates apiKey.

func (*DocstoreAuth) Generate

func (a *DocstoreAuth) Generate(ctx context.Context, domID string, isGlobalAdmin bool, note string) (*APIKey, error)

Generate generates a new APIKey and inserts it into datastore.

func (*DocstoreAuth) Open

func (a *DocstoreAuth) Open() error

Open opens a.coll once.

type NextKeyFunc

type NextKeyFunc func() string

NextKeyFunc generates next key.

type SpecialAuth

type SpecialAuth struct{}

SpecialAuth is a dummy Authenticator for tests.

func (*SpecialAuth) AuthFunc

func (*SpecialAuth) AuthFunc(_ context.Context, apiKey string, _ map[string]string) bool

AuthFunc returns (apiKey == "12345").

func (*SpecialAuth) Close

func (*SpecialAuth) Close() error

Close returns nil.

Jump to

Keyboard shortcuts

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