auth

package
v0.0.0-...-3d0596a Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithClaims

func ContextWithClaims(ctx context.Context, c *Claims) context.Context

ContextWithClaims store claims in context

func CreateToken

func CreateToken(ctx context.Context, secret string, u *model.User) (string, error)

CreateToken from user and sign it

func Init

func Init(_ *config.Config, store Store) http.HandlerFunc

Init create admin user

func Login

func Login(cfg *config.Config, store Store) http.HandlerFunc

Login with email/password credentials

func Root

func Root(cfg *config.Config, store Store) http.HandlerFunc

Root check login availability and update jwt if present valid

func Router

func Router(cfg *config.Config, store Store) func(chi.Router)

Router return auth section router

func WithClaims

func WithClaims(cfg *config.Config, required, onlyAdmin bool) func(http.Handler) http.Handler

WithClaims middleware check Authorization header and try to parse token

Require tracing.WithSpan

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	UserID  bson.ObjectId `json:"userId"`
	Email   string        `json:"email"`
	IsAdmin bool          `json:"isAdmin"`
}

Claims of authorization token

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) (*Claims, bool)

ClaimsFromContext try to extract authorization claims from context

type Store

type Store interface {
	GetUserCount(context.Context) (int, error)
	GetUserByID(context.Context, bson.ObjectId) (*model.User, error)
	GetUserByEmail(context.Context, string) (*model.User, error)
	CreateUser(context.Context, *model.User) error
}

Store is a interface of store required in package auth

Jump to

Keyboard shortcuts

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