Documentation ¶
Index ¶
- Variables
- func ContextGetUser[T any](r *http.Request) T
- func ContextSetUser[T any](r *http.Request, user T) *http.Request
- func CreateInviteToken(payload map[string]any) (string, error)
- func CreateSessionManager(db *sql.DB) *scs.SessionManager
- func Decrypt(ciphertext string) (map[string]any, error)
- func Encrypt(data map[string]any) (string, error)
- func GetSessionMiddleware[T any](sessionManager *scs.SessionManager, userExistsFn getUserExistsFn[T]) func(next http.Handler) http.Handler
- func VerifyInviteToken(token string) (map[string]any, error)
- type GetOrCreateUser
- type OidcController
Constants ¶
This section is empty.
Variables ¶
var ErrAuthCodeNotFound = errors.New("authorization code not found")
ErrAuthCodeNotFound is returned when the authorization code is not found in the request.
var ErrDecryption = errors.New("failed to decrypt data")
var ErrEncryption = errors.New("failed to encrypt data")
var ErrInvalidInviteToken = errors.New("invalid invite token")
ErrInvalidInviteToken is returned when the invite token is invalid.
var ErrInvalidPayload = errors.New("invalid payload")
var ErrInvalidState = errors.New("invalid state")
ErrInvalidState is returned when the state is invalid.
var ErrInviteExpiresAt = errors.New("invite token has expired")
var ErrNoCode = errors.New("no code")
ErrNoCode is returned when the code is not found in the request.
var ErrNoIDToken = errors.New("no id token")
ErrNoIDToken is returned when the id token is not found in the response.
var ErrTokenExchangeFailed = errors.New("token exchange failed")
ErrTokenExchangeFailed is returned when the token exchange fails.
Functions ¶
func ContextGetUser ¶
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 ¶
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 CreateSessionManager ¶
func GetSessionMiddleware ¶
Types ¶
type GetOrCreateUser ¶
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)