auth

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 15 Imported by: 0

README

📜 Caesar Auth

Caesar is a Go web framework, designed for productivity. It takes inspiration from traditional web frameworks such as Ruby on Rails, Laravel, Django, Phoenix, AdonisJS, etc.

Documentation

Index

Constants

View Source
const (
	SESSION_NAME      = "caesar_session"
	SESSION_VALUE_KEY = "user_id"
	USER_CONTEXT_KEY  = "user"
)

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func HashPassword

func HashPassword(password string) (string, error)

func RetrieveUserFromCtx

func RetrieveUserFromCtx[T any](ctx *caesar.CaesarCtx) (*T, error)

RetrieveUserFromCtx is a function that retrieves the user from the context.

Types

type Auth

type Auth struct {
	*AuthCfg
	Social *SocialAuth
	// contains filtered or unexported fields
}

func NewAuth

func NewAuth(cfg *AuthCfg) *Auth

func (*Auth) AuthMiddleware

func (auth *Auth) AuthMiddleware(ctx *caesar.CaesarCtx) error

func (*Auth) Authenticate

func (a *Auth) Authenticate(ctx *caesar.CaesarCtx, user any) error

Authenticate is a method that sets the user in the session. The session consists in a http.Cookie that is set in the client's browser.

func (*Auth) AuthenticateRequest

func (auth *Auth) AuthenticateRequest(ctx *caesar.CaesarCtx) error

func (*Auth) GenerateJWT

func (auth *Auth) GenerateJWT(user any) (string, error)

GenerateJWT is a method that generates a JWT token for the user.

func (*Auth) SignOut

func (auth *Auth) SignOut(ctx *caesar.CaesarCtx) error

SignOut is a method that removes the user from the session.

func (*Auth) SilentMiddleware

func (auth *Auth) SilentMiddleware(ctx *caesar.CaesarCtx) error

SilentMiddleware is a middleware that injects the user into the context.

type AuthCfg

type AuthCfg struct {
	Key             string
	MaxAge          time.Duration
	JWTSigningKey   []byte
	JWTExpiration   time.Duration
	SocialProviders *map[string]SocialAuthProvider
	UserProvider    func(ctx context.Context, userID any) (any, error)
	RedirectTo      string
}

type SocialAuth

type SocialAuth struct {
	Providers map[string]SocialAuthProvider
}

func NewSocialAuth

func NewSocialAuth(store *sessions.CookieStore, providers map[string]SocialAuthProvider) *SocialAuth

func (*SocialAuth) Use

func (s *SocialAuth) Use(provider string) *SocialAuthProvider

type SocialAuthProvider

type SocialAuthProvider struct {
	Key         string
	Secret      string
	CallbackURL string
	Scopes      []string
	// contains filtered or unexported fields
}

func (*SocialAuthProvider) Callback

func (p *SocialAuthProvider) Callback(ctx *core.CaesarCtx) (*goth.User, error)

func (*SocialAuthProvider) Redirect

func (p *SocialAuthProvider) Redirect(ctx *core.CaesarCtx) error

Jump to

Keyboard shortcuts

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