auth: github.com/go-pkgz/auth Index | Files | Directories

package auth

import "github.com/go-pkgz/auth"

Package auth provides "social login" with Github, Google, Facebook and Yandex as well as custom auth providers.

Index

Package Files

auth.go

type Opts Uses

type Opts struct {
    SecretReader   token.Secret        // reader returns secret for given site id (aud), required
    ClaimsUpd      token.ClaimsUpdater // updater for jwt to add/modify values stored in the token
    SecureCookies  bool                // makes jwt cookie secure
    TokenDuration  time.Duration       // token's TTL, refreshed automatically
    CookieDuration time.Duration       // cookie's TTL. This cookie stores JWT token

    DisableXSRF bool // disable XSRF protection, useful for testing/debugging
    DisableIAT  bool // disable IssuedAt claim

    // optional (custom) names for cookies and headers
    JWTCookieName  string // default "JWT"
    JWTHeaderKey   string // default "X-JWT"
    XSRFCookieName string // default "XSRF-TOKEN"
    XSRFHeaderKey  string // default "X-XSRF-TOKEN"

    Issuer string // optional value for iss claim, usually the application name, default "go-pkgz/auth"

    URL       string          // root url for the rest service, i.e. http://blah.example.com, required
    Validator token.Validator // validator allows to reject some valid tokens with user-defined logic

    AvatarStore       avatar.Store // store to save/load avatars, required
    AvatarResizeLimit int          // resize avatar's limit in pixels
    AvatarRoutePath   string       // avatar routing prefix, i.e. "/api/v1/avatar", default `/avatar`

    AdminPasswd    string                  // if presented, allows basic auth with user admin and given password
    AudienceReader token.Audience          // list of allowed aud values, default (empty) allows any
    Logger         logger.L                // logger interface, default is no logging at all
    RefreshCache   middleware.RefreshCache // optional cache to keep refreshed tokens
}

Opts is a full set of all parameters to initialize Service

type Service Uses

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

Service provides higher level wrapper allowing to construct everything and get back token middleware

func NewService Uses

func NewService(opts Opts) (res *Service)

NewService initializes everything

func (*Service) AddDirectProvider Uses

func (s *Service) AddDirectProvider(name string, credChecker provider.CredChecker)

AddDirectProvider adds provider with direct check against data store it doesn't do any handshake and uses provided credChecker to verify user and password from the request

func (*Service) AddProvider Uses

func (s *Service) AddProvider(name string, cid string, csecret string)

AddProvider adds provider for given name

func (*Service) AvatarProxy Uses

func (s *Service) AvatarProxy() *avatar.Proxy

AvatarProxy returns stored in service

func (*Service) DevAuth Uses

func (s *Service) DevAuth() (*provider.DevAuthServer, error)

DevAuth makes dev oauth2 server, for testing and development only!

func (*Service) Handlers Uses

func (s *Service) Handlers() (authHandler http.Handler, avatarHandler http.Handler)

Handlers gets http.Handler for all providers and avatars

func (*Service) Middleware Uses

func (s *Service) Middleware() middleware.Authenticator

Middleware returns auth middleware

func (*Service) Provider Uses

func (s *Service) Provider(name string) (provider.Service, error)

Provider gets provider by name

func (*Service) Providers Uses

func (s *Service) Providers() []provider.Service

Providers gets all registered providers

func (*Service) TokenService Uses

func (s *Service) TokenService() *token.Service

TokenService returns token.Service

Directories

PathSynopsis
avatarPackage avatar implements avatart proxy for oauth and defines store interface and implements local (fs), gridfs (mongo) and boltdb stores.
_example
loggerPackage logger defines interface for logging.
middlewarePackage middleware provides login middlewares: - Auth: adds auth from session and populates user info - Trace: populates user info if token presented - AdminOnly: restrict access to admin users only
provider
token

Package auth imports 11 packages (graph) and is imported by 1 packages. Updated 2019-04-11. Refresh now. Tools for package owners.