4 {-# OPTIONS_HADDOCK prune #-}
6 -- |Manipulation of WWW authorization.
7 module Network.HTTP.Lucu.Authorization
14 , authCredentialP -- private
17 import qualified Data.ByteString.Base64 as B64
18 import qualified Data.ByteString.Char8 as C8
19 import Network.HTTP.Lucu.Parser
20 import Network.HTTP.Lucu.Parser.Http
21 import Network.HTTP.Lucu.Utils
22 import Prelude.Unicode
24 -- |Authorization challenge to be sent to client with
25 -- \"WWW-Authenticate\" header. See
26 -- 'Network.HTTP.Lucu.Resource.setWWWAuthenticate'.
28 = BasicAuthChallenge Realm
31 -- |'Realm' is just a string which must not contain any non-ASCII letters.
34 -- |Authorization credential to be sent by client with
35 -- \"Authorization\" header. See
36 -- 'Network.HTTP.Lucu.Resource.getAuthorization'.
38 = BasicAuthCredential UserID Password
41 -- |'UserID' is just a string which must not contain colon and any
45 -- |'Password' is just a string which must not contain any non-ASCII
47 type Password = String
49 instance Show AuthChallenge where
50 show (BasicAuthChallenge realm)
51 = "Basic realm=" ⧺ quoteStr realm
53 authCredentialP ∷ Parser AuthCredential
59 $ satisfy (\c → (c ≥ 'a' ∧ c ≤ 'z') ∨
65 case break (≡ ':') (decode b64) of
67 → return (BasicAuthCredential uid password)
70 decode ∷ String → String
71 decode = C8.unpack ∘ B64.decodeLenient ∘ C8.pack