fiberauth

package module
v0.0.0-...-c9003b7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 11 Imported by: 0

README

fiberauth

⚡️🔒 Plug and play JWT authentication module for Fiber

⚙️ Installation

go get -u github.com/modugo/fiberauth

⚡️ Quickstart

package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/modugo/fiberauth"
)

func main() {
	app := fiber.New()

	fiberauth.Init(app, fiberauth.Config{
		WithSignIn:           true,
		WithSignUp:           true,
		WithRefresh:          true,
		WithLogout:           true,
		Entity:               Auth{},
		JWTSecret:            []byte("1234"),
		AccessTokenDuration:  1 * time.Hour,
		RefreshTokenDuration: 24 * time.Hour,
		WithRefreshToken:     true,
		WithCookie:           true,
	})

	app.Get("/", func(c *fiber.Ctx) error {
		return c.SendString("Hello, World 👋!")
	})

	app.Listen(":8080")
}

⚙️ Configuration

You can configure fiberauth easily with the fiberauth.Config, see below for know how to configure it :

Name Type Usage
WithSignIn bool Enable/Disable Sign-In endpoint
WithSignUp bool Enable/Disable Sign-Up endpoint
WithRefresh bool Enable/Disable Refresh endpoint
WithLogout bool Enable/Disable Logout endpoint
Entity interface A struct contains all methods in Entity interface
JWTSecret []byte Private secret key for JWT
AccessTokenDuration time.Duration Define access token duration
RefreshTokenDuration time.Duration Define refresh token duration
WithRefreshToken bool Enable/Disable refresh token feature
WithCookie bool Enable/Disable cookie-based JWT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLoginFromRefreshToken

func GetLoginFromRefreshToken(token string) string

func Init

func Init(app *fiber.App, cfg services.Configer, handlers ...fiber.Handler)

Types

type AccessTokenConfig

type AccessTokenConfig struct {
	SecretKey  []byte
	Duration   time.Duration
	Repository services.AccessTokenRepository
}

func (AccessTokenConfig) GetDuration

func (a AccessTokenConfig) GetDuration() time.Duration

func (AccessTokenConfig) GetRepository

func (AccessTokenConfig) GetSecretKey

func (a AccessTokenConfig) GetSecretKey() []byte

type Config

type Config struct {
	AccessToken  services.AccessTokenConfiger
	RefreshToken services.RefreshTokenConfiger
	Register     services.RegisterConfiger
	Factors      services.FactorsConfiger
	WithCookie   bool
	WithSignUp   bool
	WithLogout   bool
}

func (Config) GetAccessToken

func (c Config) GetAccessToken() services.AccessTokenConfiger

func (Config) GetFactors

func (c Config) GetFactors() services.FactorsConfiger

func (Config) GetRefreshToken

func (c Config) GetRefreshToken() services.RefreshTokenConfiger

func (Config) GetRegister

func (c Config) GetRegister() services.RegisterConfiger

func (Config) GetWithCookie

func (c Config) GetWithCookie() bool

func (Config) GetWithLogout

func (c Config) GetWithLogout() bool

func (Config) GetWithSignUp

func (c Config) GetWithSignUp() bool

func (Config) Init

func (c Config) Init() services.Configer

type FactorsConfig

type FactorsConfig struct {
	IsEnabled  bool
	SecretKey  []byte
	Duration   time.Duration
	Repository services.FactorsRepository
	TOTP       internalService.TOTPConfiger
	SMS        internalService.SMSConfiger
}

func (FactorsConfig) GetDuration

func (f FactorsConfig) GetDuration() time.Duration

func (FactorsConfig) GetIsEnabled

func (f FactorsConfig) GetIsEnabled() bool

func (FactorsConfig) GetRepository

func (f FactorsConfig) GetRepository() services.FactorsRepository

func (FactorsConfig) GetSMS

func (FactorsConfig) GetSecretKey

func (f FactorsConfig) GetSecretKey() []byte

func (FactorsConfig) GetTOTP

func (FactorsConfig) Init

type RefreshTokenConfig

type RefreshTokenConfig struct {
	IsEnabled  bool
	Duration   time.Duration
	Repository services.RefreshTokenRepository
}

func (RefreshTokenConfig) GetDuration

func (r RefreshTokenConfig) GetDuration() time.Duration

func (RefreshTokenConfig) GetIsEnabled

func (r RefreshTokenConfig) GetIsEnabled() bool

func (RefreshTokenConfig) GetRepository

type RegisterConfig

type RegisterConfig struct {
	IsEnabled  bool
	Repository services.RegisterRepository
}

func (RegisterConfig) GetIsEnabled

func (r RegisterConfig) GetIsEnabled() bool

func (RegisterConfig) GetRepository

func (r RegisterConfig) GetRepository() services.RegisterRepository

type SMSConfig

type SMSConfig struct {
	IsEnabled  bool
	Repository services.SMSRepository
}

func (SMSConfig) GetIsEnabled

func (s SMSConfig) GetIsEnabled() bool

func (SMSConfig) GetRepository

func (s SMSConfig) GetRepository() services.SMSRepository

type TOTPConfig

type TOTPConfig struct {
	IsEnabled  bool
	Issuer     string
	Repository services.TOTPRepository
}

func (TOTPConfig) GetIsEnabled

func (t TOTPConfig) GetIsEnabled() bool

func (TOTPConfig) GetIssuer

func (t TOTPConfig) GetIssuer() string

func (TOTPConfig) GetRepository

func (t TOTPConfig) GetRepository() services.TOTPRepository

Directories

Path Synopsis
internal
middlewares

Jump to

Keyboard shortcuts

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