oidc: the server becomes a relying party, and devices can carry an account
Echolot delegates identity to whatever IdP the operator already runs and stores no passwords - no hashing, no reset flow, no lockout policy, and no credential database to lose. For a tool people self-host next to other services, that is the difference between one more service and one more thing that can leak someone's password. Verification is stdlib-only, matching the server's no-dependency rule. Longer than jwt.Parse, and auditable in one sitting. The part that matters is the algorithm allow-list: taking `alg` from the token is the classic forgery, so it is fixed in code. Tests cover the real attacks against a genuine signer - a self-contained IdP with real keys, because a mock that returns success proves nothing about a verifier: alg=none, HS256/RS256 confusion, a payload swapped under a valid signature, a token addressed to another client, a token from another issuer, expired and future-dated tokens, and discovery that renames the issuer (which would otherwise have us fetch a stranger's keys believing they were the provider's). With no admin group configured nobody is an admin. An operator who has not said who may administer the server has not thereby said "anyone who can log in". Device and account stay separate concepts: enrollment admits a device (operator's token), signing in attributes it to a person (POST /v1/account/link, device credential plus ID token - both required, neither substitutes). uploads=account now means what it says instead of refusing everyone, and signing in does not override uploads=off. The profile advertises the sign-in configuration so the app can offer the button only when there is something behind it, and drive PKCE without anyone typing an issuer URL. A discovery failure is reported rather than hidden, so "configured but the provider is not answering" is distinguishable from "not configured". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
57a5ef8796
commit
ce6d0c2f64
@@ -37,8 +37,19 @@ type Device struct {
|
||||
Credential string `json:"credential"`
|
||||
Enrolled time.Time `json:"enrolled"`
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// The account this device belongs to, as issuer#subject — empty when nobody has signed in
|
||||
// on it. Enrollment and sign-in are deliberately separate: a device is admitted by an
|
||||
// operator's token, and only later (if ever) associated with a person. Servers that accept
|
||||
// anonymous uploads never need the second step.
|
||||
AccountID string `json:"account_id,omitempty"`
|
||||
AccountName string `json:"account_name,omitempty"`
|
||||
LinkedAt time.Time `json:"linked_at,omitempty"`
|
||||
}
|
||||
|
||||
// LinkedToAccount reports whether a person has signed in on this device.
|
||||
func (d Device) LinkedToAccount() bool { return d.AccountID != "" }
|
||||
|
||||
type Store struct {
|
||||
mu sync.Mutex
|
||||
path string
|
||||
@@ -126,6 +137,46 @@ func (s *Store) Redeem(token, name string) (*Device, error) {
|
||||
}
|
||||
|
||||
// DeviceByCredential authenticates a bearer credential.
|
||||
// LinkAccount ties a device to a signed-in identity, or clears it when accountID is empty.
|
||||
func (s *Store) LinkAccount(deviceID, accountID, displayName string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
for i := range s.data.Devices {
|
||||
if s.data.Devices[i].ID != deviceID {
|
||||
continue
|
||||
}
|
||||
s.data.Devices[i].AccountID = accountID
|
||||
s.data.Devices[i].AccountName = displayName
|
||||
if accountID == "" {
|
||||
s.data.Devices[i].LinkedAt = time.Time{}
|
||||
} else {
|
||||
s.data.Devices[i].LinkedAt = time.Now().UTC()
|
||||
}
|
||||
return s.save()
|
||||
}
|
||||
return errors.New("no such device")
|
||||
}
|
||||
|
||||
// Devices returns a copy of the device list, for the admin UI.
|
||||
func (s *Store) Devices() []Device {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return append([]Device(nil), s.data.Devices...)
|
||||
}
|
||||
|
||||
// DeleteDevice revokes a device: its credential stops working immediately.
|
||||
func (s *Store) DeleteDevice(id string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
for i := range s.data.Devices {
|
||||
if s.data.Devices[i].ID == id {
|
||||
s.data.Devices = append(s.data.Devices[:i], s.data.Devices[i+1:]...)
|
||||
return s.save()
|
||||
}
|
||||
}
|
||||
return errors.New("no such device")
|
||||
}
|
||||
|
||||
func (s *Store) DeviceByCredential(cred string) *Device {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user