authentication

package
v0.0.0-...-45c59c8 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

AuthMiddleware is our middleware to check our token is valid. Returning a 401 status to the client if it is not valid.

func CommonMiddleware

func CommonMiddleware(next http.Handler) http.Handler

func NewHTTPServer

func NewHTTPServer(ctx context.Context, e Endpoints, h Handler) http.Handler

Types

type Endpoints

type Endpoints interface {
	LoginEndpoint() endpoint.Endpoint
}

func InitEndpoints

func InitEndpoints(service Service) Endpoints

type Handler

type Handler interface {
	MainPageHandler(w http.ResponseWriter, r *http.Request)
	LoginPageHandler(w http.ResponseWriter, r *http.Request)
}

func InitHandler

func InitHandler(googleOauthConfig *oauth2.Config, oauthStateString string) Handler

type LoginRequest

type LoginRequest struct {
	State string `json:"state" validate:"required"`
	Code  string `json:"code" validate:"required"`
}

type LoginResponse

type LoginResponse struct {
	Token        string `json:"token"`
	IsRegistered bool   `json:"is_registered"`
}

type Repository

type Repository interface {
	GetUserIDByEmail(ctx context.Context, email string) (string, error)
	CreateUser(ctx context.Context, c *User) error
	UpdateProfile(ctx context.Context, id string, updateMap map[string]interface{}) (*User, error)
}

func InitRepository

func InitRepository(db *gorm.DB) Repository

type Service

type Service interface {
	Login(ctx context.Context, state, code string) (string, bool, error)
}

func InitService

func InitService(repo Repository, logger log.Logger, googleOauthConfig *oauth2.Config, oauthStateString string, secretKey string) Service

type User

type User struct {
	ID          string     `json:"id" db:"id"`
	Email       string     `json:"email" db:"email"`
	Name        string     `json:"name" db:"name"`
	PhoneNumber string     `json:"phone_number" db:"phone_number"`
	BirthDate   *time.Time `json:"birth_date" db:"birth_date"`
}

Jump to

Keyboard shortcuts

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