auth

package module
v0.0.0-...-3f34fde Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 23 Imported by: 0

README

auth

Build Status | codecov | Go Report Card | GoDoc

A service that allows you to get a new session token and when invalid refresh the session token (WST, Web Security Token) github.

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

With support for

  • Get session
  • Refresh session with refresh token

Endpoints

  • Get Session:

    Method: GET

    Route: http://localhost:8001/api/v1/auth/p/get-session

    Body:

    {
        "email": "joaosoft@gmail.com",
        "password": "698dc19d489c4e4db73e28a713eab07b"
    }
    
  • Refresh session:

    Method: PUT

    Route: http://localhost:8001/api/v1/auth/p/get-session

    Headers:

    Authorization: Bearer 53464673625464434c557442584467316144776f4d574530535842475258466e54444e624c6a4230504352495877.53464673625542424d45386d5755596f53305532516d7841624455764d46786c505439615a30596b52567368543263775a44677562554d7a4e4338324d31737564575642545542505354466a556964455155315163577378597a633554533953586c56755155306a576b74424d6d34745654466f4a6a704f51564a6a627a67734a7935744f5377684a47396e51564d73633239474b4751755355526c6158416c4c436777.4f56737a4e57417350436c71534370695655516a62304a6e546d6f725657413551445976526d676c4a6b52725845684e625678524e6b6b32624664304e4367775a5759744c6a5a796231417662536b6f
    

Dependecy Management

Dependency

Project dependencies are managed using Dep. Read more about Dep.

  • Get dependency manager: go get github.com/joaosoft/dependency
  • Install dependencies: dependency get
Go
go get github.com/joaosoft/auth

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotFound             = errors.New(errors.LevelError, 1, "user not found")
	ErrorInvalidBodyParameter = errors.New(errors.LevelError, 2, "invalid body parameter '%s'")
)
View Source
var ErrorHandler = func(context *validator.ValidatorContext, validationData *validator.ValidationData) error {
	if err, ok := errs[validationData.ErrorData.Code]; ok {
		var regx = regexp.MustCompile(regexForMissingParms)
		matches := regx.FindAllStringIndex(err.Message, -1)

		if len(matches) > 0 {

			if len(validationData.ErrorData.Arguments) < len(matches) {
				validationData.ErrorData.Arguments = append(validationData.ErrorData.Arguments, validationData.Name)
			}

			err = err.Format(validationData.ErrorData.Arguments...)
		}

		return err
	}
	return nil
}

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Auth *AuthConfig `json:"auth"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type Auth

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

func NewAuth

func NewAuth(options ...AuthOption) (*Auth, error)

NewAuth ...

func (*Auth) Reconfigure

func (auth *Auth) Reconfigure(options ...AuthOption)

Reconfigure ...

func (*Auth) Start

func (auth *Auth) Start() error

Start ...

func (*Auth) Stop

func (auth *Auth) Stop() error

Stop ...

type AuthConfig

type AuthConfig struct {
	Host              string                     `json:"host"`
	Dbr               *dbr.DbrConfig             `json:"dbr"`
	TokenKey          string                     `json:"token_key"`
	ExpirationMinutes int64                      `json:"expiration_minutes"`
	Migration         *migration.MigrationConfig `json:"migration"`
	Log               struct {
		Level string `json:"level"`
	} `json:"log"`
}

AuthConfig ...

type AuthOption

type AuthOption func(auth *Auth)

AuthOption ...

func WithConfiguration

func WithConfiguration(config *AuthConfig) AuthOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) AuthOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) AuthOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) AuthOption

WithManager ...

type ErrorResponse

type ErrorResponse struct {
	Code    web.Status `json:"code,omitempty"`
	Message string     `json:"message,omitempty"`
	Cause   string     `json:"cause,omitempty"`
}

type SessionResponse

type SessionResponse struct {
	TokenType    string `json:"token_type"`
	Token        string `json:"token"`
	RefreshToken string `json:"refresh_token"`
}

type SignUpResponse

type SignUpResponse struct {
	IdUser string `json:"id_user" db:"id_user"`
}

type User

type User struct {
	IdUser       string    `json:"id_user" db:"id_user"`
	FirstName    string    `json:"first_name" db:"first_name"`
	LastName     string    `json:"last_name" db:"last_name"`
	Email        string    `json:"email" db:"email"`
	PasswordHash string    `json:"-" db.write:"password_hash"`
	RefreshToken string    `json:"refresh_token" db:"refresh_token"`
	Active       bool      `json:"active" db:"active"`
	CreatedAt    time.Time `json:"created_at" db:"created_at"`
	UpdatedAt    time.Time `json:"updated_at" db:"updated_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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