oauthserver

package module
v0.0.0-...-35d2586 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2018 License: MIT Imports: 10 Imported by: 0

README

oauthserver

Server that handles OAuth 2.0 requests

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfigCtxKey = &contextKey{"Config"}
	ErrorCtxKey  = &contextKey{"Error"}
)

Functions

func NewContext

func NewContext(ctx context.Context, c *Config, err error) context.Context

Types

type Authenticator

type Authenticator interface {
	Authenticate(username, password string, scope []string) (conf *Config, err error)
}

type Config

type Config struct {
	// ClientID is the application's ID.
	ClientID interface{}

	// Scope specifies optional requested permissions.
	Scopes []string
}

func FromContext

func FromContext(ctx context.Context) (*Config, error)

func (Config) HasScope

func (c Config) HasScope(scope string) bool

type FileAuthenticator

type FileAuthenticator struct {
}

func NewFileAuthenticator

func NewFileAuthenticator() *FileAuthenticator

func (*FileAuthenticator) Authenticate

func (f *FileAuthenticator) Authenticate(username, password string, scope []string) (conf *Config, err error)

type JWTTokenGenerator

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

func NewJWTTokenGenerator

func NewJWTTokenGenerator(alg string, signKey interface{}, verifyKey interface{}, expireIn time.Duration) *JWTTokenGenerator

func (*JWTTokenGenerator) Create

func (j *JWTTokenGenerator) Create(c *Config) (*oauth2.Token, error)

func (*JWTTokenGenerator) Validate

func (j *JWTTokenGenerator) Validate(token string) (*Config, error)

type Server

type Server struct {
	Generator     TokenGenerator
	Authenticator Authenticator
}

func New

func New(generator TokenGenerator, authenticator Authenticator) *Server

func (*Server) Authenticate

func (s *Server) Authenticate(w http.ResponseWriter, r *http.Request)

func (*Server) FetchToken

func (s *Server) FetchToken(next http.Handler) http.Handler

func (*Server) RequireToken

func (s *Server) RequireToken(next http.Handler) http.Handler

func (*Server) RequireTokenScopes

func (s *Server) RequireTokenScopes(scopes []string) func(next http.Handler) http.Handler

type TokenGenerator

type TokenGenerator interface {
	Create(*Config) (*oauth2.Token, error)
	Validate(token string) (*Config, error)
}

Jump to

Keyboard shortcuts

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