Documentation
¶
Index ¶
- Constants
- Variables
- func WithLogger(logger *slog.Logger) func(*Gosesh)
- func WithNow(fn func() time.Time) func(*Gosesh)
- func WithOAuth2StateCookieName(name string) func(*Gosesh)
- func WithOrigin(origin *url.URL) func(*Gosesh)
- func WithSessionActiveDuration(d time.Duration) func(*Gosesh)
- func WithSessionCookieName(name string) func(*Gosesh)
- func WithSessionIdleDuration(d time.Duration) func(*Gosesh)
- type CallbackHandler
- type CreateSessionRequest
- type Gosesh
- func (gs *Gosesh) Authenticate(next http.Handler) http.Handler
- func (gs *Gosesh) AuthenticateAndRefresh(next http.Handler) http.Handler
- func (gs *Gosesh) Host() string
- func (gs *Gosesh) Logout(w http.ResponseWriter, r *http.Request) (*http.Request, error)
- func (gs *Gosesh) LogoutHandler(completeHandler http.HandlerFunc) http.HandlerFunc
- func (gs *Gosesh) OAuth2Begin(oauthCfg *oauth2.Config) http.HandlerFunc
- func (gs *Gosesh) OAuth2Callback(user OAuth2User, config *oauth2.Config, handler CallbackHandler) http.HandlerFunc
- func (gs *Gosesh) RequireAuthentication(next http.Handler) http.Handler
- func (gs *Gosesh) Scheme() string
- type IDParser
- type Identifier
- type NewOpts
- type OAuth2Credentials
- type OAuth2User
- type Session
- type Storer
- type UpdateSessionValues
Constants ¶
View Source
const (
SessionContextKey contextKey = "session"
)
Variables ¶
View Source
var ( ErrFailedGettingStateCookie = errors.New("failed getting state cookie") ErrInvalidStateCookie = errors.New("invalid state cookie") ErrFailedExchangingToken = errors.New("failed exchanging token") ErrFailedUnmarshallingData = errors.New("failed unmarshalling data") ErrFailedUpsertingUser = errors.New("failed upserting user") ErrFailedCreatingSession = errors.New("failed creating session") )
Functions ¶
func WithLogger ¶
func WithOrigin ¶
func WithSessionCookieName ¶
func WithSessionIdleDuration ¶
Types ¶
type CallbackHandler ¶ added in v0.0.3
type CallbackHandler func(http.ResponseWriter, *http.Request, error)
type CreateSessionRequest ¶
type CreateSessionRequest struct { UserID Identifier IdleAt time.Time ExpireAt time.Time }
type Gosesh ¶
type Gosesh struct {
// contains filtered or unexported fields
}
func (*Gosesh) AuthenticateAndRefresh ¶
func (*Gosesh) LogoutHandler ¶
func (gs *Gosesh) LogoutHandler(completeHandler http.HandlerFunc) http.HandlerFunc
func (*Gosesh) OAuth2Begin ¶
func (gs *Gosesh) OAuth2Begin(oauthCfg *oauth2.Config) http.HandlerFunc
func (*Gosesh) OAuth2Callback ¶
func (gs *Gosesh) OAuth2Callback(user OAuth2User, config *oauth2.Config, handler CallbackHandler) http.HandlerFunc
Create a handler that will handle the OAuth2 callback. This handler performs the token exchange and retrieves user data from the provider. When the OAuth2 flow has completed, the input `handler` will be invoked, with the error value set to nil if the flow was successful, or an error if it was not.
func (*Gosesh) RequireAuthentication ¶
type IDParser ¶
type IDParser interface {
Parse([]byte) (Identifier, error)
}
type Identifier ¶
type OAuth2Credentials ¶
type OAuth2User ¶
type OAuth2User interface { Identifier // Uniquely identifies the user within the OAuth2 provider's system. Request(ctx context.Context, accessToken string) (*http.Response, error) Unmarshal(b []byte) error }
Represents a user presented by an OAuth2 provider. Note that this is separate from a user as persisted in your system.
type Session ¶
type Session struct { ID Identifier UserID Identifier IdleAt time.Time ExpireAt time.Time }
type Storer ¶
type Storer interface { UpsertUser(ctx context.Context, user OAuth2User) (Identifier, error) CreateSession(ctx context.Context, req CreateSessionRequest) (*Session, error) GetSession(ctx context.Context, sessionID Identifier) (*Session, error) UpdateSession(ctx context.Context, sessionID Identifier, req UpdateSessionValues) (*Session, error) DeleteSession(ctx context.Context, sessionID Identifier) error DeleteUserSessions(ctx context.Context, userID Identifier) (int, error) }
Click to show internal directories.
Click to hide internal directories.