nethttp

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package nethttp adapts goauth to standard-library JSON HTTP handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthContext

func AuthContext(ctx context.Context) (goauth.AuthContext, bool)

func WriteError

func WriteError(w http.ResponseWriter, err error)

Types

type Adapter

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

func New

func New(runtime Runtime) (*Adapter, error)

func (*Adapter) ChangePassword

func (a *Adapter) ChangePassword(w http.ResponseWriter, r *http.Request)

func (*Adapter) ConfirmEmailChange

func (a *Adapter) ConfirmEmailChange(w http.ResponseWriter, r *http.Request)

func (*Adapter) Login

func (a *Adapter) Login(w http.ResponseWriter, r *http.Request)

func (*Adapter) Logout

func (a *Adapter) Logout(w http.ResponseWriter, r *http.Request)

func (*Adapter) LogoutAll

func (a *Adapter) LogoutAll(w http.ResponseWriter, r *http.Request)

func (*Adapter) Refresh

func (a *Adapter) Refresh(w http.ResponseWriter, r *http.Request)

func (*Adapter) Register

func (a *Adapter) Register(w http.ResponseWriter, r *http.Request)

func (*Adapter) RequestEmailChange

func (a *Adapter) RequestEmailChange(w http.ResponseWriter, r *http.Request)

func (*Adapter) RequestPasswordReset

func (a *Adapter) RequestPasswordReset(w http.ResponseWriter, r *http.Request)

func (*Adapter) RequireRealm

func (a *Adapter) RequireRealm(realm goauth.Realm, options RealmMiddlewareOptions) func(http.Handler) http.Handler

func (*Adapter) ResetPassword

func (a *Adapter) ResetPassword(w http.ResponseWriter, r *http.Request)

func (*Adapter) SendEmailChallenge

func (a *Adapter) SendEmailChallenge(w http.ResponseWriter, r *http.Request)

func (*Adapter) VerifyEmailChallenge

func (a *Adapter) VerifyEmailChallenge(w http.ResponseWriter, r *http.Request)

type ErrorBody

type ErrorBody struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type ErrorResponse

type ErrorResponse struct {
	Error ErrorBody `json:"error"`
}

type PasswordEmailChangeRuntime

type PasswordEmailChangeRuntime interface {
	RequestEmailChangeWithPassword(ctx context.Context, request goauth.PasswordEmailChangeRequest) error
}

PasswordEmailChangeRuntime is an optional capability required only by the email-change handler. Older Runtime implementations remain source compatible, but this handler fails closed instead of calling the trusted subject-only API.

type RealmMiddlewareOptions

type RealmMiddlewareOptions struct {
	// OfflineJWT skips revocation checks; use only where up to five minutes of
	// stale authorization is explicitly acceptable.
	OfflineJWT        bool
	AllowConfirmation bool
}

RealmMiddlewareOptions controls session verification. The zero value checks persisted session and subject state on every request.

type Runtime

type Runtime interface {
	Logout(ctx context.Context, subjectID goauth.SubjectID, sessionID string) error
	LogoutAll(ctx context.Context, subjectID goauth.SubjectID) (int64, error)
	ChangePassword(ctx context.Context, request goauth.ChangePasswordRequest) (goauth.Account, error)
	RequestEmailChange(ctx context.Context, subjectID goauth.SubjectID, email string) error
	ConfirmEmailChange(ctx context.Context, subjectID goauth.SubjectID, code string) (goauth.Account, error)
	Register(ctx context.Context, request goauth.RegisterRequest) (goauth.RegisterResult, error)
	Login(ctx context.Context, request goauth.LoginRequest) (goauth.LoginResult, error)
	Refresh(ctx context.Context, refreshToken string) (goauth.TokenPair, error)
	AuthenticateSession(ctx context.Context, accessToken string) (goauth.AuthContext, error)
	VerifyJWT(ctx context.Context, accessToken string) (goauth.AuthContext, error)
	RequestPasswordReset(ctx context.Context, email string) error
	ResetPassword(ctx context.Context, token, newPassword string) error
	SendEmailChallenge(ctx context.Context, subjectID goauth.SubjectID, purpose goauth.EmailChallengePurpose) error
	VerifyEmailChallenge(
		ctx context.Context,
		subjectID goauth.SubjectID,
		purpose goauth.EmailChallengePurpose,
		code string,
	) (goauth.Account, error)
}

Jump to

Keyboard shortcuts

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