auth

package
v0.0.0-...-b93ae0a Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotAuthorized      = errors.New("not authorized")
	ErrInsufficientPrivileges = errors.New("insufficient privileges")
	ErrIDNotFound             = errors.New("user ID not found")
	ErrIDNoValid              = errors.New("user ID is not valid")
	ErrRoleNotFound           = errors.New("user role not found")
	ErrRoleNoValid            = errors.New("user role is not valid")
)

Errors

Functions

func Authenticator

func Authenticator(next http.Handler) http.Handler

Authenticator is an authentication middleware.

func GetID

func GetID(r *http.Request) (id string, err error)

GetID returns user ID from the request context.

func GetRole

func GetRole(r *http.Request) (role user.Role, err error)

GetRole returns user role from the request context.

func WithID

func WithID(id ...string) func(next http.Handler) http.Handler

WithID validate user id from the request context.

func WithRole

func WithRole(roles ...user.Role) func(next http.Handler) http.Handler

WithRole validate user role from request context.

Types

type FirebaseAuth

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

FirebaseAuth is a wrapper to firebase client.

func NewFirebaseAuth

func NewFirebaseAuth(ctx context.Context, credentialsFilePath string) (*FirebaseAuth, error)

NewFirebaseAuth returns a new FirebaseAuth with configuration.

func (*FirebaseAuth) GetFirebaseClient

func (fa *FirebaseAuth) GetFirebaseClient() *auth.Client

GetFirebaseClient returns the FireBase's Client.

func (*FirebaseAuth) GetFirebaseUser

func (fa *FirebaseAuth) GetFirebaseUser(ctx context.Context, uid string) (user.User, error)

GetFirebaseUser returns an user from firebase auth.

func (*FirebaseAuth) WithToken

func (fa *FirebaseAuth) WithToken(next http.Handler) http.Handler

WithToken Allows you to verify the token provided by FireBase from the Header.

type Key

type Key string

Key to request context.

const (
	RoleKey Key = "role"
	IDKey   Key = "id"
	UIDKey  Key = "uid"
	UserKey Key = "user"
)

Context keys.

type Repository

type Repository interface {
	GetFirebaseUser(ctx context.Context, uid string) (user.User, error)
	WithToken(next http.Handler) http.Handler
	GetFirebaseClient() *auth.Client
}

Repository firebase repository

Directories

Path Synopsis
Package mock_auth is a generated GoMock package.
Package mock_auth is a generated GoMock package.

Jump to

Keyboard shortcuts

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