Files
superbrain/internal/oidc/config.go
T
Andrew S Erwin 4b6a58118e Rename Go module to gitea.federated.computer/Federated_Computer/superbrain
The Gitea repository was renamed brain -> superbrain (server-side redirect
already in place; local origin updated at 0.3.5). Carry the rename through
for accurate identity, the 0.3.2 precedent: go.mod + every internal import,
the agent's outbound User-Agent contact URL, README/RUNNING clone URLs and
local notes. CHANGELOG history entries stay as written. Pure identifier
rename, no runtime behavior change; verified with build + vet + unit tests
and the full database integration suite under -race.
2026-11-24 16:02:01 -06:00

78 lines
2.3 KiB
Go

package oidc
// Authelia OIDC configuration (STUB-AWARE). Porting guide 3.8.
//
// Authelia sign-in is only enabled when all three env vars hold real values:
// OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET
//
// Empty values or obvious placeholders (REPLACE_ME, example.com, changeme, ...)
// are treated as "not connected": the Authelia provider is not registered, the
// login button is shown disabled, and email/password login keeps working.
//
// See docs/AUTHELIA.md for the full connection guide.
import (
"os"
"regexp"
"strings"
"gitea.federated.computer/Federated_Computer/superbrain/internal/config"
)
var placeholderPatterns = []*regexp.Regexp{
regexp.MustCompile(`replace[_-]?me`),
regexp.MustCompile(`example\.(com|org|net)`),
regexp.MustCompile(`changeme`),
regexp.MustCompile(`placeholder`),
regexp.MustCompile(`^<.*>$`),
regexp.MustCompile(`^your[_-]`),
regexp.MustCompile(`^todo$`),
}
func isRealValue(value string) bool {
v := strings.ToLower(strings.TrimSpace(value))
if v == "" {
return false
}
for _, p := range placeholderPatterns {
if p.MatchString(v) {
return false
}
}
return true
}
// OidcStatus mirrors lib/oidc-config.ts. Enabled only when all three env
// values are real (non-placeholder). Never exposes the secret.
type OidcStatus struct {
Enabled bool
IssuerSet bool
ClientIDSet bool
ClientSecretSet bool
Issuer *string
}
// Status returns the current OIDC configuration state. AUTH_MODE=password
// disables OIDC regardless of the variables (multi-tenant shape: signup
// only, no Authelia); the identity bridge refuses provisioning to match.
func Status() OidcStatus {
issuerSet := isRealValue(os.Getenv("OIDC_ISSUER"))
clientIdSet := isRealValue(os.Getenv("OIDC_CLIENT_ID"))
clientSecretSet := isRealValue(os.Getenv("OIDC_CLIENT_SECRET"))
var issuer *string
if issuerSet {
v := strings.TrimSpace(os.Getenv("OIDC_ISSUER"))
issuer = &v
}
return OidcStatus{
Enabled: config.AuthMode() != "password" && issuerSet && clientIdSet && clientSecretSet,
IssuerSet: issuerSet,
ClientIDSet: clientIdSet,
ClientSecretSet: clientSecretSet,
Issuer: issuer,
}
}
// CallbackPath is where Authelia sends the OIDC code back.
const CallbackPath = "/api/auth/callback/authelia"