betalinkauth

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: CC0-1.0 Imports: 17 Imported by: 0

README

BetaLink aims to simplify the process of connecting beta-testers with project owners seeking feedback on their applications or products. This microservice is part of the larger BetaLink ecosystem, focusing on managing authentication on a credentials level, and providing APIs for seamless integration with other services.

Getting Started

These instructions will give you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on deploying the project on a live system.

Prerequisites

Requirements for the software and other tools to build, test and push

Installing

Steps to set up the development environment:

Clone the repository:

git clone https://github.com/BragdonD/betalink-auth.git
cd betalink-auth

Running the tests

Explain how to run the automated tests for this system

Sample Tests

Explain what these tests test and why

Give an example
Style test

Checks if the best practices and the right coding style has been used.

Give an example

Deployment

Add additional notes to deploy this on a live system

Built With

  • Golang - Core programming language
  • PostgreSQL - Database for persistent storage
  • Swagger/OpenAPI - API documentation
  • Docker - Containerization

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use Semantic Versioning for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the CC0 1.0 Universal Creative Commons License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code is used
  • Inspiration
  • etc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExpiredTokenError is an error that represents an expired token
	ExpiredTokenError = &ValidationError{
		Message: "Token has expired",
	}
)

Functions

func ComparePassword

func ComparePassword(password, hash string) error

ComparePassword compares a password with a hash

func GenerateAccessToken

func GenerateAccessToken(userID string, roles []string, secret string, validity time.Duration) (string, error)

GenerateAccessToken generates an access token with user-specific data

func GenerateJWT

func GenerateJWT(data map[string]interface{}, secret string) (string, error)

GenerateJWT generates a JWT token containing the provided data

func GenerateRefreshToken added in v0.2.0

func GenerateRefreshToken(sessionID string, createdAt, expiresAt time.Time, secret string) (string, error)

GenerateRefreshToken generates a refresh token

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a password using bcrypt algorithm

func ValidateAccessToken

func ValidateAccessToken(token, secret string) (jwt.MapClaims, error)

ValidateAccessToken validates an access token

func ValidateEmail

func ValidateEmail(email string) (bool, error)

ValidateEmail validates an email address based on the following rules: - Must contain an @ symbol - Must contain a period - Must have at least 2 characters after the period

func ValidatePassword

func ValidatePassword(password string) (bool, error)

ValidatePassword validates a password based on the following rules: - Must be at least 8 characters long - Must contain at least one lowercase letter - Must contain at least one uppercase letter - Must contain at least one digit - Must contain at least one special character

func ValidateRefreshToken added in v0.2.0

func ValidateRefreshToken(token, secret string) (jwt.MapClaims, error)

ValidateRefreshToken validates a refresh token

Types

type CreateEmailVerificationParams

type CreateEmailVerificationParams struct {
	UserID            pgtype.UUID
	VerificationToken string
}

type CreatePasswordRecoveryParams

type CreatePasswordRecoveryParams struct {
	UserID        pgtype.UUID
	RecoveryToken string
}

type CreateSessionParams added in v0.2.0

type CreateSessionParams struct {
	UserID    pgtype.UUID
	CreatedAt pgtype.Timestamptz
	UpdatedAt pgtype.Timestamptz
	ExpiresAt pgtype.Timestamptz
}

type CreateUserLoginDataParams

type CreateUserLoginDataParams struct {
	UserID        pgtype.UUID
	Email         string
	Passwordhash  string
	Passwordsalt  string
	Hashalgorithm string
}

type CreateUserParams

type CreateUserParams struct {
	FirstName string
	LastName  string
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type Emailverification

type Emailverification struct {
	UserID            pgtype.UUID
	VerificationToken string
	CreatedAt         pgtype.Timestamp
	Used              bool
}

type Externalloginprovider

type Externalloginprovider struct {
	ProviderID       pgtype.UUID
	ProviderName     string
	ProviderEndpoint string
}

type GetUserByIdRow

type GetUserByIdRow struct {
	UserID    pgtype.UUID
	FirstName string
	LastName  string
}

type Hashalgorithm

type Hashalgorithm struct {
	Hashalgorithm string
}

type IDTokens

type IDTokens struct {
	AccessToken  string
	RefreshToken string
}

IDTokens is a struct containing the access and refresh tokens

type Passwordrecovery

type Passwordrecovery struct {
	UserID        pgtype.UUID
	RecoveryToken string
	CreatedAt     pgtype.Timestamp
	Used          bool
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateEmailVerification

func (q *Queries) CreateEmailVerification(ctx context.Context, arg CreateEmailVerificationParams) error

func (*Queries) CreatePasswordRecovery

func (q *Queries) CreatePasswordRecovery(ctx context.Context, arg CreatePasswordRecoveryParams) error

func (*Queries) CreateSession added in v0.2.0

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (pgtype.UUID, error)

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error)

func (*Queries) CreateUserLoginData

func (q *Queries) CreateUserLoginData(ctx context.Context, arg CreateUserLoginDataParams) error

func (*Queries) DeleteSession added in v0.2.0

func (q *Queries) DeleteSession(ctx context.Context, sessionID pgtype.UUID) error

func (*Queries) GetLoginDataByEmail

func (q *Queries) GetLoginDataByEmail(ctx context.Context, email string) (Userslogindatum, error)

func (*Queries) GetSessionById added in v0.2.0

func (q *Queries) GetSessionById(ctx context.Context, sessionID pgtype.UUID) (Session, error)

func (*Queries) GetUserById

func (q *Queries) GetUserById(ctx context.Context, userID pgtype.UUID) (GetUserByIdRow, error)

func (*Queries) Test_UpdateSessionExpiresAt added in v0.2.0

func (q *Queries) Test_UpdateSessionExpiresAt(ctx context.Context, arg Test_UpdateSessionExpiresAtParams) error

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type Router

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

Router is the http router for the auth service

func NewRouter

func NewRouter(logger *betalinklogger.Logger, ginRouter *gin.Engine, usecases *Usecases) *Router

NewRouter creates a new Router instance

type ServerError

type ServerError struct {
	Message string
}

ServerError is an error type that represents an internal server error

func (*ServerError) Error

func (e *ServerError) Error() string

Error returns the error message

type Session added in v0.2.0

type Session struct {
	SessionID pgtype.UUID
	UserID    pgtype.UUID
	CreatedAt pgtype.Timestamptz
	UpdatedAt pgtype.Timestamptz
	ExpiresAt pgtype.Timestamptz
}

type Test_UpdateSessionExpiresAtParams added in v0.2.0

type Test_UpdateSessionExpiresAtParams struct {
	ExpiresAt pgtype.Timestamptz
	SessionID pgtype.UUID
}

type Usecases

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

Usecases is the usecases for the auth service

func NewUsecase

func NewUsecase(logger *betalinklogger.Logger, queries *Queries) *Usecases

NewUsecase creates a new Usecases instance

func (*Usecases) LoginUser

func (u *Usecases) LoginUser(ctx context.Context, email, password string) (*IDTokens, error)

LoginUser checks the user credentials

func (*Usecases) RefreshAccessToken added in v0.2.0

func (u *Usecases) RefreshAccessToken(ctx context.Context, refreshToken string) (*IDTokens, error)

func (*Usecases) RegisterUser

func (u *Usecases) RegisterUser(ctx context.Context, firstname, lastname, email, password string) error

RegisterUser registers a new user in the database

func (*Usecases) ValidateAccessToken added in v0.2.0

func (u *Usecases) ValidateAccessToken(ctx context.Context, accessToken string) (*UserData, error)

ValidateAccessToken validates an access token

type User

type User struct {
	UserID    pgtype.UUID
	FirstName string
	LastName  string
	CreatedAt pgtype.Timestamp
	UpdatedAt pgtype.Timestamp
}

type UserData added in v0.2.0

type UserData struct {
	UserID    pgtype.UUID
	FirstName string
	LastName  string
}

UserData represents the user information retrieved from the auth server

type Userloginexternal

type Userloginexternal struct {
	UserID               pgtype.UUID
	ProviderID           pgtype.UUID
	ProviderAccessToken  string
	ProviderRefreshToken string
}

type Userslogindatum

type Userslogindatum struct {
	UserID        pgtype.UUID
	Email         string
	Passwordhash  string
	Passwordsalt  string
	Hashalgorithm string
}

type ValidationError

type ValidationError struct {
	Message string
}

ValidationError is an error type that represents a validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns the error message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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