Public read-only share link (no login / no OIDC) (#41) (#43)
Build image / build-and-push (push) Successful in 8s
Build image / build-and-push (push) Successful in 8s
Per-garden public read-only link: unauthenticated GET /api/v1/public/gardens/:token (no requireAuth, no OIDC), owner-only enable/rotate/disable, and a /g/$token page rendering GardenCanvas read-only. Review fixes: redact plant owner ids, Cache-Control: no-store, 400 on malformed body, shared resetTransient store action. Closes #41. Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #43.
This commit is contained in:
@@ -59,16 +59,25 @@ func formatTime(t time.Time) string { return t.UTC().Format(timeLayout) }
|
||||
// parseTime parses a canonical pansy timestamp.
|
||||
func parseTime(s string) (time.Time, error) { return time.Parse(timeLayout, s) }
|
||||
|
||||
// newSessionToken returns a fresh URL-safe random bearer token (32 bytes of
|
||||
// entropy). The raw token goes in the cookie; only its hash is persisted.
|
||||
func newSessionToken() (string, error) {
|
||||
b := make([]byte, 32)
|
||||
// randToken returns nBytes of cryptographic randomness as a URL-safe string.
|
||||
func randToken(nBytes int) (string, error) {
|
||||
b := make([]byte, nBytes)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return "", fmt.Errorf("service: generate session token: %w", err)
|
||||
return "", fmt.Errorf("service: generate token: %w", err)
|
||||
}
|
||||
return base64.RawURLEncoding.EncodeToString(b), nil
|
||||
}
|
||||
|
||||
// newSessionToken returns a fresh URL-safe random bearer token (32 bytes of
|
||||
// entropy). The raw token goes in the cookie; only its hash is persisted.
|
||||
func newSessionToken() (string, error) { return randToken(32) }
|
||||
|
||||
// newPublicToken returns a fresh unguessable token for a garden's public share
|
||||
// link (18 bytes → 144 bits; a 24-char URL segment). Unlike a session token it's
|
||||
// stored raw (it must be shown back to the owner to copy) and grants only
|
||||
// read-only access to one garden.
|
||||
func newPublicToken() (string, error) { return randToken(18) }
|
||||
|
||||
// hashToken maps a raw bearer token to the hex sha256 stored as the session's
|
||||
// primary key.
|
||||
func hashToken(raw string) string {
|
||||
|
||||
Reference in New Issue
Block a user