summaryrefslogtreecommitdiff
path: root/authentication.rkt
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-12-03 20:57:26 +0100
committerMarius Peter <dev@marius-peter.com>2025-12-03 20:57:26 +0100
commit9338724460b3a86eefdd0085c43bd0b75e73a4e2 (patch)
tree3e00289c32113e5fe7fb205c6f38df3e88efc18b /authentication.rkt
parent71c22e872b1b4c24cf7ce0ea86451930cc9cbd83 (diff)
Parameterize authentication credentials.
Diffstat (limited to 'authentication.rkt')
-rw-r--r--authentication.rkt26
1 files changed, 16 insertions, 10 deletions
diff --git a/authentication.rkt b/authentication.rkt
index 9e9400b..9a15976 100644
--- a/authentication.rkt
+++ b/authentication.rkt
@@ -1,27 +1,33 @@
#lang racket
-(provide make-auth-dispatch)
+(provide authentication-credentials-defined?
+ make-auth-dispatch)
(require web-server/http
web-server/http/basic-auth)
-(define ferti-user
- (or (getenv "FERTI_USER") (error 'authentication "FERTI_USER environment variable is not set")))
-(define ferti-pass
- (or (getenv "FERTI_PASS") (error 'authentication "FERTI_PASS environment variable is not set")))
+(define ferti-user (make-parameter (getenv "FERTI_USER")))
+(define ferti-pass (make-parameter (getenv "FERTI_PASS")))
+
+(define (authentication-credentials-defined?)
+ (and (ferti-user) (ferti-pass)))
(define (make-auth-dispatch handler)
- (lambda (req)
- (if (authorized? req)
- (handler req)
- (unauthorized-response))))
+ (if (authentication-credentials-defined?)
+ (lambda (req)
+ (if (authorized? req)
+ (handler req)
+ (unauthorized-response)))
+ (error
+ 'authentication
+ "Undefined authentication credentials (FERTI_USER and FERTI_PASS environment variables)")))
(define (authorized? req)
(match (request->basic-credentials req)
[(cons user-b pass-b)
(define user (bytes->string/utf-8 user-b))
(define pass (bytes->string/utf-8 pass-b))
- (and (string=? user ferti-user) (string=? pass ferti-pass))]
+ (and (string=? user (ferti-user)) (string=? pass (ferti-pass)))]
[_ #f]))
(define (unauthorized-response)
Copyright 2019--2026 Marius PETER