Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoginURL ¶
func LoginURL() string
LoginURL returns the SSO login URL path. The frontend getter prepends REST_API_URL + "/" before this value.
func Middleware ¶
Middleware checks the X-Auth-Token header and injects the user into context. When auth is enabled, requests without a valid token get 401. When auth is disabled, this middleware is a no-op.
func SplitScopes ¶
SplitScopes splits a comma-separated scopes string.
Types ¶
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers provides HTTP handlers for the auth flow.
func NewHandlers ¶
func NewHandlers(oauth *OAuthClient, tokens *TokenStore) *Handlers
NewHandlers creates auth HTTP handlers.
func (*Handlers) RegisterProtectedRoutes ¶
func (h *Handlers) RegisterProtectedRoutes(mux *http.ServeMux, authMiddleware func(http.Handler) http.Handler)
RegisterProtectedRoutes registers routes that need auth middleware.
func (*Handlers) RegisterRoutes ¶
RegisterRoutes registers auth endpoints on the mux. These routes are public (no auth middleware).
type OAuthClient ¶
type OAuthClient struct {
// contains filtered or unexported fields
}
OAuthClient wraps an oauth2.Config and provider-specific user mapping.
func NewOAuthClient ¶
func NewOAuthClient(provider, providerURL, clientID, clientSecret, callbackURL, scopes string) (*OAuthClient, error)
NewOAuthClient builds an OAuthClient from auth configuration. For OIDC-compatible providers it attempts discovery via .well-known/openid-configuration. For GitHub it uses hardcoded endpoints.
func (*OAuthClient) AuthCodeURL ¶
func (c *OAuthClient) AuthCodeURL(state string) string
AuthCodeURL returns the URL to redirect the user to for authorization.
type ProviderEndpoints ¶
ProviderEndpoints holds OAuth2 endpoint URLs and user info URL.
type TokenClaims ¶
type TokenClaims struct {
jwt.RegisteredClaims
Provider string `json:"provider"`
Username string `json:"username"`
Email string `json:"email"`
Avatar string `json:"avatar"`
}
TokenClaims are the JWT claims stored in internal tokens.
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
TokenStore creates and validates internal JWT tokens.
func NewTokenStore ¶
func NewTokenStore(secret string) *TokenStore
NewTokenStore creates a new TokenStore with the given HMAC secret.
func (*TokenStore) Create ¶
func (s *TokenStore) Create(u User) (string, error)
Create issues a new JWT token for the given user.
type User ¶
type User struct {
Provider string `json:"provider"`
Username string `json:"username"`
Email string `json:"email"`
Avatar string `json:"avatar"`
}
User represents an authenticated user.
func GuestUser ¶
func GuestUser() User
GuestUser returns the default guest user when auth is disabled.
func UserFromContext ¶
UserFromContext extracts the authenticated user from the request context.