authorization

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 13, 2018 License: AGPL-3.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ScopeAll = "all"
)

Scopes

Variables

View Source
var (
	ErrNotAuthorized       = errors.New("not authorized")
	ErrInvalidClient       = errors.New("invalid client")
	ErrInvalidAuth         = errors.New("invalid auth")
	ErrMissingRedirect     = errors.New("missing redirect_uri")
	ErrInvalidResponseType = errors.New("response_type unsupported")
)

Error Values

View Source
var (
	ErrExpectStringValue = errors.New("TokenCache expects the value to be a string")
	ErrExpectStringSlice = errors.New("TokenCache expects the value list to be a []string")
)

Errors

Functions

func NewRequestChecker

func NewRequestChecker(cache *TokenCache, users *user.Registry) common.RequestChecker

NewRequestChecker returns a Bearer Token request checker

Types

type Handler

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

Handler provides OAuth2 capabilities.

func NewHandler

func NewHandler(options *Options) *Handler

NewHandler creates and initializes a new OAuthHandler

func (*Handler) Authorized

func (h *Handler) Authorized(r *http.Request) ([]string, error)

Authorized returns the authorized scopes for a request, or an error if the request does not have sufficient authorization.

func (*Handler) RegisterAPI

func (h *Handler) RegisterAPI(root string) http.Handler

RegisterAPI returns a router that handles OAuth routes.

type Options

type Options struct {
	TokenTTL   time.Duration
	GrantTTL   time.Duration
	Cache      store.Cache
	TokenCache *TokenCache
	Clients    *client.Registry
	Users      *user.Registry
}

Options encapsulates OAuth Handler options.

type TokenCache

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

TokenCache provides a forward/backward lookup cache for clients and tokens.

There is an n->1 relationship between tokens and client id, so this cache abstracts managing the lookup and expiration of tokens per client id.

func NewTokenCache

func NewTokenCache(clients store.Cache, tokens store.Cache) *TokenCache

NewTokenCache creates a new TokenCache from the provided store.Cache's representing client tokens, and token clients.

func (*TokenCache) Delete

func (c *TokenCache) Delete(token string) error

Delete removes token from the cache.

func (*TokenCache) Get

func (c *TokenCache) Get(token string) (interface{}, error)

Get expects to be given a token, and to return a client id.

func (*TokenCache) Put

func (c *TokenCache) Put(key string, value interface{}) error

Put expects value to be a string token.

func (*TokenCache) PutUntil

func (c *TokenCache) PutUntil(time time.Time, key string, value interface{}) error

PutUntil expects value to be a string token.

Jump to

Keyboard shortcuts

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