auth

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Admin

func Admin(s *scs.SessionManager) web.Middleware

Authenticate returns a middleware intended to protect routes which require an administrator.

func Authenticate

func Authenticate(s *scs.SessionManager) web.Middleware

Authenticate returns a middleware intended to protect routes which require an authenticated user.

func HandleLogin

func HandleLogin(db *sqlx.DB, session *scs.SessionManager) web.Handler

HandleLogin makes a session for the user if the passed credentials are correct.

func HandleLogout

func HandleLogout(session *scs.SessionManager) web.Handler

HandleLogout cancels the user's session.

func HandleOauthCallback

func HandleOauthCallback(db *sqlx.DB, session *scs.SessionManager, provs map[string]Provider, redirect string) web.Handler

HandleOauthLogin completes the Oauth flow for the user and creates a new authenticated session.

func HandleOauthLogin

func HandleOauthLogin(session *scs.SessionManager, provs map[string]Provider) web.Handler

HandleOauthLogin starts the Oauth flow to authenticate the user. It returns the URL to complete the authentication on the specified external provider.

func HandleSignup

func HandleSignup(db *sqlx.DB, session *scs.SessionManager, activationRequired bool) web.Handler

HandleSignup tries to register the user with the passed information. If activationRequired is true, users need to confirm the registration via email.

func LoadAndSave

func LoadAndSave(s *scs.SessionManager) web.Middleware

LoadAndSave updates the user's session if there was a change.

func MakeProviders

func MakeProviders(ctx context.Context, cfg []ProviderConfig) (map[string]Provider, error)

MakeProviders builds supported Oauth providers.

func SaveUserSession

func SaveUserSession(ctx context.Context, session *scs.SessionManager, userID string, role string) error

SaveUserSession saves the passed user in the current session.

Types

type Provider

type Provider struct {
	*oauth2.Config
	*oidc.Provider
}

Provider wraps an external Oauth provider.

type ProviderConfig

type ProviderConfig struct {
	Name        string
	Client      string
	Secret      string
	URL         string
	RedirectURL string
}

ProviderConfig contains the information needed to setup an Oauth provider.

type UserInfo

type UserInfo struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

UserInfo includes the information of a user to be retrieved from external providers.

Jump to

Keyboard shortcuts

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