auth: Index | Files | Directories

package auth

import ""

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


Package Files


type Client Uses

type Client struct {
    Cid     string
    Csecret string

Client is a type of auth client

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"
    JWTQuery       string // default "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., 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`
    UseGravatar       bool         // for email based auth (verified provider) use gravatar service

    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) AddCustomProvider Uses

func (s *Service) AddCustomProvider(name string, client Client, copts provider.CustomHandlerOpt)

AddCustomProvider adds custom provider (e.g.

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, cid, csecret string)

AddProvider adds provider for given name

func (*Service) AddVerifProvider Uses

func (s *Service) AddVerifProvider(name, msgTmpl string, sender provider.Sender)

AddVerifProvider adds provider user's verification sent by sender

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, 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


avatarPackage avatar implements avatart proxy for oauth and defines store interface and implements local (fs), gridfs (mongo) and boltdb stores.
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

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