Documentation
¶
Index ¶
- Constants
- Variables
- func AuthFromCookie(auth *Auth, cookieName, redirectPath string, next http.Handler) http.Handler
- func ClearAuthCookie(w http.ResponseWriter, cookieName string, cookieSecure bool)
- func NewBearerResourceHandler(auth *Auth) func(http.ResponseWriter, *http.Request)
- func NewSessionResourceHandler(auth *Auth, cookieName, redirectPath string) http.Handler
- func NewTokenGetHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
- func NewTokenStoreHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
- func NewTokenUpdateHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
- func NewTokensListHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
- func RegisterRoutes(router RouteRegistrar, auth *Auth)
- func SignOutHandler(cookieName string, cookieSecure bool, redirectPath string) func(http.ResponseWriter, *http.Request)
- func WriteJSON(w http.ResponseWriter, status int, payload interface{})
- type Auth
- func (a *Auth) AddProvider(provider Provider)
- func (a *Auth) CallbackHandler() func(http.ResponseWriter, *http.Request)
- func (a *Auth) LoginHandler() func(http.ResponseWriter, *http.Request)
- func (a *Auth) RequireAuth(next http.Handler) http.Handler
- func (a *Auth) SetAuthResultHandler(h AuthResultHandler)
- func (a *Auth) SetDevMode(devMode bool)
- func (a *Auth) SetUserHandler(h UserHandler)
- func (a *Auth) VerifyRequest(r *http.Request) (*VerifiedUser, error)
- func (a *Auth) VerifyToken(tokenString string) (*VerifiedUser, error)
- type AuthResult
- type AuthResultHandler
- type AuthResultHandlerFunc
- type EmbedConfig
- type Provider
- type RouteRegistrar
- type Runtime
- func (r *Runtime) Authenticate(email, password string) (*User, error)
- func (r *Runtime) Close() error
- func (r *Runtime) ConsumePasswordReset(email, code string) (*User, error)
- func (r *Runtime) CreatePasswordResetCode(email string) (string, error)
- func (r *Runtime) CreateUser(email, password string) (*User, error)
- func (r *Runtime) DeleteUser(userID string) error
- func (r *Runtime) Handler() http.Handler
- func (r *Runtime) IssueDeviceToken(userID string) (*TokenPair, error)
- func (r *Runtime) IssueRecoveryToken(userID string) (*TokenPair, error)
- func (r *Runtime) IssueTokens(userID string) (*TokenPair, error)
- func (r *Runtime) Refresh(refreshToken string) (*TokenPair, error)
- func (r *Runtime) RequestPasswordReset(email string) error
- func (r *Runtime) Revoke(accessOrRefresh string) error
- func (r *Runtime) SessionAuthResultHandler(redirectPath string) AuthResultHandler
- func (r *Runtime) UpdatePassword(userID, password string) error
- func (r *Runtime) UserByID(id string) (*User, error)
- func (r *Runtime) VerifyAccessToken(raw string) (*VerifiedUser, error)
- func (r *Runtime) VerifyRequestAccess(req *http.Request) (*VerifiedUser, error)
- type SMTPConfig
- type SessionAuthResultOptions
- type TokenPair
- type TokenRecord
- type TokenStore
- type User
- type UserHandler
- type UserHandlerFunc
- type VerifiedUser
Constants ¶
Variables ¶
View Source
var ( ErrMissingJWTSecret = errors.New("jwt secret is required") ErrWeakJWTSecret = errors.New("jwt secret must be at least 32 bytes") )
View Source
var ( ErrPasswordTooShort = store.ErrPasswordTooShort ErrUserExists = store.ErrUserExists ErrUsernameExists = store.ErrUsernameExists ErrInvalidCredentials = store.ErrInvalidCredentials ErrUserNotFound = store.ErrUserNotFound ErrInvalidOTP = store.ErrInvalidOTP )
Functions ¶
func AuthFromCookie ¶
func ClearAuthCookie ¶
func ClearAuthCookie(w http.ResponseWriter, cookieName string, cookieSecure bool)
func NewBearerResourceHandler ¶
func NewBearerResourceHandler(auth *Auth) func(http.ResponseWriter, *http.Request)
func NewTokenGetHandler ¶
func NewTokenGetHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
func NewTokenStoreHandler ¶
func NewTokenStoreHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
func NewTokenUpdateHandler ¶
func NewTokenUpdateHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
func NewTokensListHandler ¶
func NewTokensListHandler(store *TokenStore) func(http.ResponseWriter, *http.Request)
func RegisterRoutes ¶
func RegisterRoutes(router RouteRegistrar, auth *Auth)
func SignOutHandler ¶
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, payload interface{})
Types ¶
type Auth ¶
type Auth struct {
Providers map[string]Provider
CookieSecure bool
// contains filtered or unexported fields
}
func (*Auth) AddProvider ¶
func (*Auth) CallbackHandler ¶
func (a *Auth) CallbackHandler() func(http.ResponseWriter, *http.Request)
func (*Auth) LoginHandler ¶
func (a *Auth) LoginHandler() func(http.ResponseWriter, *http.Request)
func (*Auth) SetAuthResultHandler ¶
func (a *Auth) SetAuthResultHandler(h AuthResultHandler)
func (*Auth) SetDevMode ¶
func (*Auth) SetUserHandler ¶
func (a *Auth) SetUserHandler(h UserHandler)
func (*Auth) VerifyRequest ¶
func (a *Auth) VerifyRequest(r *http.Request) (*VerifiedUser, error)
func (*Auth) VerifyToken ¶
func (a *Auth) VerifyToken(tokenString string) (*VerifiedUser, error)
type AuthResult ¶
type AuthResultHandler ¶
type AuthResultHandler interface {
HandleAuthResult(ctx context.Context, w http.ResponseWriter, r *http.Request, result *AuthResult) error
}
func NewSessionAuthResultHandler ¶
func NewSessionAuthResultHandler(store *TokenStore, opts SessionAuthResultOptions) AuthResultHandler
type AuthResultHandlerFunc ¶
type AuthResultHandlerFunc func(context.Context, http.ResponseWriter, *http.Request, *AuthResult) error
func (AuthResultHandlerFunc) HandleAuthResult ¶
func (f AuthResultHandlerFunc) HandleAuthResult(ctx context.Context, w http.ResponseWriter, r *http.Request, result *AuthResult) error
type EmbedConfig ¶
type EmbedConfig struct {
StorageType string
ConnectionString string
IssuerURL string
KeyDir string
ClientID string
ClientSecret string
RedirectURIs []string
CORSOrigins []string
DevMode bool
SMTP SMTPConfig
AdminToken string
PrivateKeyJWTHosts []string
JWTSecret []byte
}
EmbedConfig configures an in-process authorization server (no extra listener).
type Provider ¶
type Provider interface {
Name() string
Config() *oauth2.Config
Verifier() *oidc.IDTokenVerifier
}
type RouteRegistrar ¶
type RouteRegistrar interface {
Handle(pattern string, handler http.Handler)
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}
RouteRegistrar is the minimum interface needed to register handlers.
type Runtime ¶
type Runtime struct {
ListenAddr string
ConfigDir string
Auth *Auth
Store *TokenStore
CookieName string
CookieSecure bool
OAuthIssuer string
OAuthClientID string
// contains filtered or unexported fields
}
Runtime exposes the configured auth runtime so callers can register their own routes.
func NewEmbedded ¶
func NewEmbedded(cfg EmbedConfig) (*Runtime, error)
NewEmbedded builds store, keys, and an OAuth HTTP handler without ListenAndServe.
func (*Runtime) Authenticate ¶
func (*Runtime) ConsumePasswordReset ¶
func (*Runtime) CreatePasswordResetCode ¶
func (*Runtime) DeleteUser ¶
func (*Runtime) IssueDeviceToken ¶
func (*Runtime) IssueRecoveryToken ¶
func (*Runtime) RequestPasswordReset ¶
func (*Runtime) SessionAuthResultHandler ¶
func (r *Runtime) SessionAuthResultHandler(redirectPath string) AuthResultHandler
func (*Runtime) UpdatePassword ¶
func (*Runtime) VerifyAccessToken ¶
func (r *Runtime) VerifyAccessToken(raw string) (*VerifiedUser, error)
func (*Runtime) VerifyRequestAccess ¶
func (r *Runtime) VerifyRequestAccess(req *http.Request) (*VerifiedUser, error)
type SMTPConfig ¶
SMTPConfig is the public mailer settings for the embedded server.
type TokenPair ¶
type TokenPair struct {
AccessToken string
RefreshToken string
TokenType string
ExpiresIn int
TokenUse string
User User
}
TokenPair is the mobile-session shape issued by the authorization server.
type TokenRecord ¶
type TokenRecord struct {
Provider string `json:"provider"`
UserSub string `json:"user_sub"`
Email string `json:"email"`
Name string `json:"name"`
SignedJWT string `json:"signed_jwt"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresAt string `json:"expires_at"`
}
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
TODO: convert to use db
func NewTokenStore ¶
func NewTokenStore() *TokenStore
func (*TokenStore) All ¶
func (s *TokenStore) All() map[string]TokenRecord
func (*TokenStore) Get ¶
func (s *TokenStore) Get(sub string) (TokenRecord, bool)
func (*TokenStore) Save ¶
func (s *TokenStore) Save(record TokenRecord)
type UserHandler ¶
type UserHandlerFunc ¶
func (UserHandlerFunc) HandleUser ¶
type VerifiedUser ¶
type VerifiedUser struct {
Subject string
Claims jwt.RegisteredClaims
Token string
TokenUse string
Email string
Scope string
}
func UserFromContext ¶
func UserFromContext(ctx context.Context) (*VerifiedUser, bool)
Click to show internal directories.
Click to hide internal directories.