3 -- |Manipulation of WWW authorization.
4 module Network.HTTP.Lucu.Authorization
11 , authCredentialP -- private
15 import qualified Codec.Binary.Base64 as B64
16 import Network.HTTP.Lucu.Parser
17 import Network.HTTP.Lucu.Parser.Http
18 import Network.HTTP.Lucu.Utils
20 -- |Authorization challenge to be sent to client with
21 -- \"WWW-Authenticate\" header. See
22 -- 'Network.HTTP.Lucu.Resource.setWWWAuthenticate'.
24 = BasicAuthChallenge Realm
27 -- |'Realm' is just a string which must not contain any non-ASCII letters.
30 -- |Authorization credential to be sent by client with
31 -- \"Authorization\" header. See
32 -- 'Network.HTTP.Lucu.Resource.getAuthorization'.
34 = BasicAuthCredential UserID Password
37 -- |'UserID' is just a string which must not contain colon and any
41 -- |'Password' is just a string which must not contain any non-ASCII
43 type Password = String
46 instance Show AuthChallenge where
47 show (BasicAuthChallenge realm)
48 = "Basic realm=" ++ quoteStr realm
51 authCredentialP :: Parser AuthCredential
52 authCredentialP = allowEOF $!
56 $ satisfy (\ c -> (c >= 'a' && c <= 'z') ||
57 (c >= 'A' && c <= 'Z') ||
58 (c >= '0' && c <= '9') ||
62 let decoded = map (toEnum . fromEnum) (B64.decode b64)
63 case break (== ':') decoded of
65 -> return (BasicAuthCredential uid password)