auth

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package auth is a generated GoMock package.

Index

Constants

View Source
const ServiceName = "auth"

Variables

View Source
var (
	ErrMissingCredentials   = errors.New("missing credentials, email and password have to be provided")
	ErrInvalidCredentials   = errors.New("invalid credentials, email/password combination wrong")
	ErrMissingRefreshToken  = errors.New("missing refresh token in JSON body")
	ErrTokenInvalid         = errors.New("token invalid")
	ErrTokenNotFound        = errors.New("token not found")
	ErrUserDoesNotExist     = errors.New("user does not exist")
	ErrInstanceDoesNotExist = errors.New("instance does not exist")
	ErrProfileDoesNotExist  = errors.New("profile does not exist")
)
View Source
var (
	ErrMissingRevokeEmail = errors.New("missing user id")
	ErrTokenRevoked       = errors.New("refresh token was revoked and is no longer valid")
)
View Source
var (
	GitCommit string
	Version   string
)

Build Variables picked up by govvv go get github.com/ahmetb/govvv

View Source
var (
	ErrInvalidEmail    = errors.New("invalid user email provided")
	ErrInvalidPassword = errors.New("invalid user password provided")
)

Functions

func LoginHandler

func LoginHandler(ctx *gin.Context, s *Service)

LoginHandler logs a user in and returs a fresh set of tokens.

func RefreshHandler

func RefreshHandler(ctx *gin.Context, s *Service)

RefreshHandler refreshes a user's access token.

func RevokeAllHandler

func RevokeAllHandler(ctx *gin.Context, s *Service)

RevokeAllHandler revokes a user's tokens for a specific instance or falls back to the authorization tokens instance.

func RevokeHandler

func RevokeHandler(ctx *gin.Context, s *Service)

RevokeHandler revokes a user's tokens for a specific instance or falls back to the authorization tokens instance.

func SignupHandler

func SignupHandler(ctx *gin.Context, s *Service)

SignupHandler creates a new user.

Types

type CredentialsBody

type CredentialsBody struct {
	InstanceURL string `json:"instance"`
	Email       string `json:"email"`
	Password    string `json:"password"`
}

CredentialsBody describes the login credentials

type DBAPI

type DBAPI interface {
	BeginTx(ctx context.Context) (*sql.Tx, error)
	Commit(tx *sql.Tx) error
	Rollback(tx *sql.Tx) error
	FindUserByEmail(ctx context.Context, email string) (*m.User, error)
	GetInstance(ctx context.Context, instanceURL string) (instance *m.Instance, err error)
	GetProfile(ctx context.Context, userID, instanceID string) (profile *m.Profile, err error)
	GetUserAndProfile(ctx context.Context, userID string, instanceURL string) (user *m.User, profile *m.Profile, err error)
	CreateProfile(ctx context.Context, tx *sql.Tx, instanceID string, user *m.User, role string) (profile *m.Profile, err error)
	CreateUser(ctx context.Context, tx *sql.Tx, name, email string, passwordHash []byte) (user *m.User, err error)
	DeleteUser(ctx context.Context, userID string) error
	SaveToken(ctx context.Context, profile *m.Profile, token string, expiresAt time.Time) error
	HasToken(ctx context.Context, userID, profileID, token string) (bool, error)
	DeleteToken(ctx context.Context, profileID string) (int64, error)
	DeleteAllTokens(ctx context.Context, userID string) (int64, error)
}

type Env

type Env struct {
	service.DBEnv
	tokens.TokenEnv
	service.HTTPEnv
	AllowOrigins []string
	// contains filtered or unexported fields
}

Env is a hierarchical environment configuration for the authentication service and it's API handlers.

func Load

func Load() (env Env, err error)

func (Env) Setup

func (env Env) Setup() (s Service, err error)

type MockDBAPI

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

MockDBAPI is a mock of DBAPI interface.

func NewMockDBAPI

func NewMockDBAPI(ctrl *gomock.Controller) *MockDBAPI

NewMockDBAPI creates a new mock instance.

func (*MockDBAPI) BeginTx

func (m *MockDBAPI) BeginTx(arg0 context.Context) (*sql.Tx, error)

BeginTx mocks base method.

func (*MockDBAPI) Commit

func (m *MockDBAPI) Commit(arg0 *sql.Tx) error

Commit mocks base method.

func (*MockDBAPI) CreateProfile

func (m *MockDBAPI) CreateProfile(arg0 context.Context, arg1 *sql.Tx, arg2 string, arg3 *dbmodels.User, arg4 string) (*dbmodels.Profile, error)

CreateProfile mocks base method.

func (*MockDBAPI) CreateUser

func (m *MockDBAPI) CreateUser(arg0 context.Context, arg1 *sql.Tx, arg2, arg3 string, arg4 []byte) (*dbmodels.User, error)

CreateUser mocks base method.

func (*MockDBAPI) DeleteAllTokens

func (m *MockDBAPI) DeleteAllTokens(arg0 context.Context, arg1 string) (int64, error)

DeleteAllTokens mocks base method.

func (*MockDBAPI) DeleteToken

func (m *MockDBAPI) DeleteToken(arg0 context.Context, arg1 string) (int64, error)

DeleteToken mocks base method.

func (*MockDBAPI) DeleteUser

func (m *MockDBAPI) DeleteUser(arg0 context.Context, arg1 string) error

DeleteUser mocks base method.

func (*MockDBAPI) EXPECT

func (m *MockDBAPI) EXPECT() *MockDBAPIMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDBAPI) FindUserByEmail

func (m *MockDBAPI) FindUserByEmail(arg0 context.Context, arg1 string) (*dbmodels.User, error)

FindUserByEmail mocks base method.

func (*MockDBAPI) GetInstance

func (m *MockDBAPI) GetInstance(arg0 context.Context, arg1 string) (*dbmodels.Instance, error)

GetInstance mocks base method.

func (*MockDBAPI) GetProfile

func (m *MockDBAPI) GetProfile(arg0 context.Context, arg1, arg2 string) (*dbmodels.Profile, error)

GetProfile mocks base method.

func (*MockDBAPI) GetUserAndProfile

func (m *MockDBAPI) GetUserAndProfile(arg0 context.Context, arg1, arg2 string) (*dbmodels.User, *dbmodels.Profile, error)

GetUserAndProfile mocks base method.

func (*MockDBAPI) HasToken

func (m *MockDBAPI) HasToken(arg0 context.Context, arg1, arg2, arg3 string) (bool, error)

HasToken mocks base method.

func (*MockDBAPI) Rollback

func (m *MockDBAPI) Rollback(arg0 *sql.Tx) error

Rollback mocks base method.

func (*MockDBAPI) SaveToken

func (m *MockDBAPI) SaveToken(arg0 context.Context, arg1 *dbmodels.Profile, arg2 string, arg3 time.Time) error

SaveToken mocks base method.

type MockDBAPIMockRecorder

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

MockDBAPIMockRecorder is the mock recorder for MockDBAPI.

func (*MockDBAPIMockRecorder) BeginTx

func (mr *MockDBAPIMockRecorder) BeginTx(arg0 interface{}) *gomock.Call

BeginTx indicates an expected call of BeginTx.

func (*MockDBAPIMockRecorder) Commit

func (mr *MockDBAPIMockRecorder) Commit(arg0 interface{}) *gomock.Call

Commit indicates an expected call of Commit.

func (*MockDBAPIMockRecorder) CreateProfile

func (mr *MockDBAPIMockRecorder) CreateProfile(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call

CreateProfile indicates an expected call of CreateProfile.

func (*MockDBAPIMockRecorder) CreateUser

func (mr *MockDBAPIMockRecorder) CreateUser(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call

CreateUser indicates an expected call of CreateUser.

func (*MockDBAPIMockRecorder) DeleteAllTokens

func (mr *MockDBAPIMockRecorder) DeleteAllTokens(arg0, arg1 interface{}) *gomock.Call

DeleteAllTokens indicates an expected call of DeleteAllTokens.

func (*MockDBAPIMockRecorder) DeleteToken

func (mr *MockDBAPIMockRecorder) DeleteToken(arg0, arg1 interface{}) *gomock.Call

DeleteToken indicates an expected call of DeleteToken.

func (*MockDBAPIMockRecorder) DeleteUser

func (mr *MockDBAPIMockRecorder) DeleteUser(arg0, arg1 interface{}) *gomock.Call

DeleteUser indicates an expected call of DeleteUser.

func (*MockDBAPIMockRecorder) FindUserByEmail

func (mr *MockDBAPIMockRecorder) FindUserByEmail(arg0, arg1 interface{}) *gomock.Call

FindUserByEmail indicates an expected call of FindUserByEmail.

func (*MockDBAPIMockRecorder) GetInstance

func (mr *MockDBAPIMockRecorder) GetInstance(arg0, arg1 interface{}) *gomock.Call

GetInstance indicates an expected call of GetInstance.

func (*MockDBAPIMockRecorder) GetProfile

func (mr *MockDBAPIMockRecorder) GetProfile(arg0, arg1, arg2 interface{}) *gomock.Call

GetProfile indicates an expected call of GetProfile.

func (*MockDBAPIMockRecorder) GetUserAndProfile

func (mr *MockDBAPIMockRecorder) GetUserAndProfile(arg0, arg1, arg2 interface{}) *gomock.Call

GetUserAndProfile indicates an expected call of GetUserAndProfile.

func (*MockDBAPIMockRecorder) HasToken

func (mr *MockDBAPIMockRecorder) HasToken(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

HasToken indicates an expected call of HasToken.

func (*MockDBAPIMockRecorder) Rollback

func (mr *MockDBAPIMockRecorder) Rollback(arg0 interface{}) *gomock.Call

Rollback indicates an expected call of Rollback.

func (*MockDBAPIMockRecorder) SaveToken

func (mr *MockDBAPIMockRecorder) SaveToken(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

SaveToken indicates an expected call of SaveToken.

type RefreshTokenBody

type RefreshTokenBody struct {
	RefreshToken string `json:"refreshToken"`
}

RefreshTokenBody describes the refresh body

type RevokeAllBody

type RevokeAllBody struct {
	Email string `json:"email"`
}

RevokeAllBody describes the user to revoke all tokens for

type RevokeBody

type RevokeBody struct {
	Email       string `json:"email"`
	InstanceURL string `json:"instance"`
}

RevokeBody describes the user/instance to revoke tokens for

type Service

type Service struct {
	Env
	service.DBConn
	DBAPI DBAPI
	service.HTTPServer
	TokenAPI     *tokens.TokenController
	AllowOrigins map[string]struct{}
}

Service offers the APIs of the authentication service. This struct holds hierarchically structured state that is shared between requests.

func Main

func Main() (authService Service, err error)

func (*Service) Login

func (s *Service) Login(ctx *gin.Context) (accessToken, refreshToken, role string, err error)

func (*Service) Refresh

func (s *Service) Refresh(ctx *gin.Context) (string, error)

func (*Service) Revoke

func (s *Service) Revoke(ctx *gin.Context) error

func (*Service) RevokeAll

func (s *Service) RevokeAll(ctx *gin.Context) error

func (*Service) Run

func (s *Service) Run(ctx context.Context) (err error)

func (*Service) Signup

func (s *Service) Signup(ctx *gin.Context) (userID string, err error)

type SignupBody

type SignupBody struct {
	InstanceURL string `json:"instance"`
	Name        string `json:"name"`
	Email       string `json:"email"`
	Password    string `json:"password"`
}

SignupBody describes the signup body with desired credentials

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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