4 {-# OPTIONS_HADDOCK prune #-}
6 -- |Manipulation of WWW authorization.
7 module Network.HTTP.Lucu.Authorization
14 , authCredentialP -- private
17 import Data.Ascii (Ascii)
18 import qualified Data.Ascii as A
19 import qualified Data.ByteString.Base64 as B64
20 import qualified Data.ByteString.Char8 as C8
21 import Network.HTTP.Lucu.Parser.Http
22 import Network.HTTP.Lucu.Utils
23 import Prelude.Unicode
25 -- |Authorization challenge to be sent to client with
26 -- \"WWW-Authenticate\" header. See
27 -- 'Network.HTTP.Lucu.Resource.setWWWAuthenticate'.
29 = BasicAuthChallenge Realm
32 -- |'Realm' is just a string which must not contain any non-ASCII letters.
35 -- |Authorization credential to be sent by client with
36 -- \"Authorization\" header. See
37 -- 'Network.HTTP.Lucu.Resource.getAuthorization'.
39 = BasicAuthCredential UserID Password
42 -- |'UserID' is just a string which must not contain colon and any
46 -- |'Password' is just a string which must not contain any non-ASCII
50 -- FIXME: Don't use String for network output.
51 instance Show AuthChallenge where
52 show (BasicAuthChallenge realm)
53 = "Basic realm=" ⧺ quoteStr realm
55 authCredentialP ∷ Parser AuthCredential
61 $ satisfy (\c → (c ≥ 'a' ∧ c ≤ 'z') ∨
67 case break (≡ ':') (decode b64) of
69 → return (BasicAuthCredential uid password)
72 decode ∷ String → String
73 decode = C8.unpack ∘ B64.decodeLenient ∘ C8.pack