Version: 4.1.5
2.4.7 Basic Authentication
(require web-server/http/basic-auth) |
An implementation of HTTP Basic Authentication.
(make-basic-auth-header realm) → header? |
realm : string? |
Returns a header that instructs the Web browser to request a username and password from the client using Basic authentication with realm as the realm.
(request->basic-credentials req) |
→ (or/c false/c (cons/c bytes? bytes?)) |
req : request? |
Returns a pair of the username and password from the authentication header in req if they are present, or #f.
Example:
#lang web-server/insta |
(define (start req) |
(match (request->basic-credentials req) |
[(cons user pass) |
`(html (head (title "Basic Auth Test")) |
(body (h1 "User: " ,(bytes->string/utf-8 user)) |
(h1 "Pass: " ,(bytes->string/utf-8 pass))))] |
[else |
(make-response/basic |
401 #"Unauthorized" (current-seconds) TEXT/HTML-MIME-TYPE |
(list |
(make-basic-auth-header |
(format "Basic Auth Test: ~a" (gensym)))))])) |