authutils

package
v0.0.0-...-e9c6563 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthCodeNotFound = errors.New("authorization code not found")

ErrAuthCodeNotFound is returned when the authorization code is not found in the request.

View Source
var ErrDecryption = errors.New("failed to decrypt data")
View Source
var ErrEncryption = errors.New("failed to encrypt data")
View Source
var ErrInvalidInviteToken = errors.New("invalid invite token")

ErrInvalidInviteToken is returned when the invite token is invalid.

View Source
var ErrInvalidPayload = errors.New("invalid payload")
View Source
var ErrInvalidState = errors.New("invalid state")

ErrInvalidState is returned when the state is invalid.

View Source
var ErrInviteExpiresAt = errors.New("invite token has expired")
View Source
var ErrNoCode = errors.New("no code")

ErrNoCode is returned when the code is not found in the request.

View Source
var ErrNoIDToken = errors.New("no id token")

ErrNoIDToken is returned when the id token is not found in the response.

View Source
var ErrTokenExchangeFailed = errors.New("token exchange failed")

ErrTokenExchangeFailed is returned when the token exchange fails.

Functions

func ContextGetUser

func ContextGetUser[T any](r *http.Request) T

The ContextGetUser() retrieves the User struct from the request context. The only time that we'll use this helper is when we logically expect there to be User struct value in the context, and if it doesn't exist it will firmly be an 'unexpected' error. As we discussed earlier in the book, it's OK to panic in those circumstances.

func ContextSetUser

func ContextSetUser[T any](r *http.Request, user T) *http.Request

The ContextSetUser() method returns a new copy of the request with the provided User struct added to the context. Note that we use our userContextKey constant as the key.

func CreateInviteToken

func CreateInviteToken(payload map[string]any) (string, error)

func CreateSessionManager

func CreateSessionManager(db *sql.DB) *scs.SessionManager

func Decrypt

func Decrypt(ciphertext string) (map[string]any, error)

Decrypt a string that was encrypted with Encrypt.

func Encrypt

func Encrypt(data map[string]any) (string, error)

Encrypt a map[string]any.

func GetSessionMiddleware

func GetSessionMiddleware[T any](
	sessionManager *scs.SessionManager,
	userExistsFn getUserExistsFn[T],
) func(next http.Handler) http.Handler

func VerifyInviteToken

func VerifyInviteToken(token string) (map[string]any, error)

Types

type GetOrCreateUser

type GetOrCreateUser[T any] func(ctx context.Context, email string, inviteTokenPayload map[string]any) (T, error)

type OidcController

type OidcController[T any] struct {
	// contains filtered or unexported fields
}

func CreateOidcController

func CreateOidcController[T any](
	sessionManager *scs.SessionManager,
	getOrCreateUserFn GetOrCreateUser[T],
) *OidcController[T]

func NewOidcController

func NewOidcController[T any](
	sessionManager *scs.SessionManager,
	fn GetOrCreateUser[T],
	config *oauth2Config,
) *OidcController[T]

func (*OidcController[T]) ProtectedRoutes

func (c *OidcController[T]) ProtectedRoutes(r httputils.Router)

func (*OidcController[T]) PublicRoutes

func (c *OidcController[T]) PublicRoutes(r httputils.Router)

Jump to

Keyboard shortcuts

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