goth

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 13 Imported by: 3

README

👻 Goth

Go Reference Go Report Card Taylor Swift

A fiber 🚀 middleware to integrate authentication to your application. It is based on a lightweight wrapper around goth.

Installation

$ go get github.com/shareed2k/goth_fiber

Examples

See examples to understand the provided interfaces.

Supported Providers

  • Amazon
  • Apple
  • Auth0
  • Azure AD
  • Battle.net
  • Bitbucket
  • Box
  • Cloud Foundry
  • Dailymotion
  • Deezer
  • DigitalOcean
  • Discord
  • Dropbox
  • Eve Online
  • Facebook
  • Fitbit
  • Gitea
  • GitHub
  • Gitlab
  • Google
  • Google+ (deprecated)
  • Heroku
  • InfluxCloud
  • Instagram
  • Intercom
  • Kakao
  • Lastfm
  • LINE
  • Linkedin
  • Mailru
  • Meetup
  • MicrosoftOnline
  • Naver
  • Nextcloud
  • Okta
  • OneDrive
  • OpenID Connect (auto discovery)
  • Oura
  • Patreon
  • Paypal
  • SalesForce
  • Shopify
  • Slack
  • Soundcloud
  • Spotify
  • Steam
  • Strava
  • Stripe
  • TikTok
  • Tumblr
  • Twitch
  • Twitter
  • Typetalk
  • Uber
  • VK
  • WeCom
  • Wepay
  • Xero
  • Yahoo
  • Yammer
  • Yandex
  • Zoom

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingProviderName is thrown if the provider cannot be determined.
	ErrMissingProviderName = errors.New("missing provider name in request")
	// ErrMissingSession is thrown if there is no active session.
	ErrMissingSession = errors.New("could not find a matching session for this request")
)
View Source
var ConfigDefault = Config{
	ErrorHandler:        defaultErrorHandler,
	ResponseFilter:      defaultResponseFilter,
	BeginAuthHandler:    BeginAuthHandler{},
	CompleteAuthHandler: CompleteAuthCompleteHandler{},
	LogoutHandler:       LogoutHandler{},
	Session:             NewSessionStore(session.New(defaultSessionConfig)),
}

ConfigDefault is the default config.

Functions

func ContextWithProvider

func ContextWithProvider(ctx *fiber.Ctx, provider string) *fiber.Ctx

ContextWithProvider returns a new request context containing the provider.

func DefaultSession

func DefaultSession() any

Return the raw store of the used default session

func GetAuthURLFromContext

func GetAuthURLFromContext(c *fiber.Ctx, session SessionStore) (string, error)

GetAuthURLFromContext returns the provider specific authentication URL.

func GetStateFromContext

func GetStateFromContext(ctx *fiber.Ctx) string

GetStateFromContext return the state that is returned during the callback.

func NewBeginAuthHandler

func NewBeginAuthHandler(config ...Config) fiber.Handler

NewBeginAuthHandler creates a new middleware handler to start authentication.

func NewCompleteAuthHandler

func NewCompleteAuthHandler(config ...Config) fiber.Handler

NewBeginCompleteAuthHandler creates a new middleware handler to complete authentication.

func NewLogoutHandler

func NewLogoutHandler(config ...Config) fiber.Handler

NewLogoutHandler returns a new default logout handler.

func NewSessionStore

func NewSessionStore(store *session.Store) *sessionStore

NewSessionStore returns a new default store based on the session middleware.

func ProviderFromContext

func ProviderFromContext(c *fiber.Ctx) string

ProviderFromContext returns the provider from the request context.

Types

type BeginAuthHandler

type BeginAuthHandler struct{}

BeginAuthHandler is the default handler to begin the authentication process.

func (BeginAuthHandler) New

New creates a new handler to begin authentication.

type CompleteAuthCompleteHandler

type CompleteAuthCompleteHandler struct{}

CompleteAuthComplete is the default handler to complete the authentication process.

func (CompleteAuthCompleteHandler) New

New creates a new handler to complete authentication.

type Config

type Config struct {
	// Next defines a function to skip this middleware when returned true.
	Next func(c *fiber.Ctx) bool

	// BeginAuthHandler is the handler to start authentication.
	BeginAuthHandler GothHandler

	// CompleteAuthHandler is the handler to complete the authentication.
	CompleteAuthHandler GothHandler

	// LogoutHandler is the handler to logout.
	LogoutHandler GothHandler

	// Session stores an authentication session.
	Session SessionStore

	// Response filter that is executed when responses need to returned.
	ResponseFilter func(c *fiber.Ctx) error

	// ErrorHandler is executed when an error is returned from fiber.Handler.
	//
	// Optional. Default: DefaultErrorHandler
	ErrorHandler fiber.ErrorHandler
}

Config caputes the configuration for running the goth middleware.

type GothHandler

type GothHandler interface {
	New(cfg Config) fiber.Handler
}

GothHandler is the interface for defining handlers for the middleware.

type LogoutHandler

type LogoutHandler struct{}

LogoutHandler is the default handler for the logout process.

func (LogoutHandler) New

func (LogoutHandler) New(cfg Config) fiber.Handler

New creates a new handler to logout.

type Params

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

Params maps the parameters of the Fiber context to the gothic context.

func (*Params) Get

func (p *Params) Get(key string) string

Get returns the value of a query paramater.

type SessionStore

type SessionStore interface {
	// Get ...
	Get(c *fiber.Ctx, key string) (string, error)
	// Update ...
	Update(c *fiber.Ctx, key, value string) error
	// Destroy ...
	Destroy(c *fiber.Ctx) error
	// Interface ...
	Interface() any
}

SessionStore is the interface to store session information for authentication.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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