OverloadedStrings
, UnicodeSyntax
#-}
--- |Manipulation of WWW authentication.
+-- |An internal module for HTTP authentication.
module Network.HTTP.Lucu.Authentication
( AuthChallenge(..)
, AuthCredential(..)
, Password
, printAuthChallenge
- , authCredentialP
+ , authCredential
)
where
+import Control.Monad
import Data.Ascii (Ascii)
import qualified Data.Ascii as A
import Data.Attoparsec.Char8
import Network.HTTP.Lucu.Utils
import Prelude.Unicode
--- |Authorization challenge to be sent to client with
--- \"WWW-Authenticate\" header. See
--- 'Network.HTTP.Lucu.Resource.setWWWAuthenticate'.
+-- |Authentication challenge to be sent to clients with
+-- \"WWW-Authenticate\" header field. See
+-- 'Network.HTTP.Lucu.setWWWAuthenticate'.
data AuthChallenge
= BasicAuthChallenge !Realm
deriving (Eq)
--- |'Realm' is just a string which must not contain any non-ASCII letters.
+-- |'Realm' is just an 'Ascii' string.
type Realm = Ascii
-- |Authorization credential to be sent by client with
--- \"Authorization\" header. See
--- 'Network.HTTP.Lucu.Resource.getAuthorization'.
+-- \"Authorization\" header. See 'Network.HTTP.Lucu.getAuthorization'.
data AuthCredential
= BasicAuthCredential !UserID !Password
deriving (Show, Eq)
--- |'UserID' is just a string which must not contain colon and any
--- non-ASCII letters.
-type UserID = Ascii
+-- |'UserID' is just an 'Ascii' string containing no colons (\':\').
+type UserID = Ascii
--- |'Password' is just a string which must not contain any non-ASCII
--- letters.
+-- |'Password' is just an 'Ascii' string.
type Password = Ascii
-- |Convert an 'AuthChallenge' to 'Ascii'.
= A.fromAsciiBuilder $
A.toAsciiBuilder "Basic realm=" ⊕ quoteStr realm
-authCredentialP ∷ Parser AuthCredential
-authCredentialP
- = do _ ← string "Basic"
+-- |'Parser' for an 'AuthCredential'.
+authCredential ∷ Parser AuthCredential
+authCredential
+ = do void $ string "Basic"
skipMany1 lws
b64 ← takeWhile1 base64
case C8.break (≡ ':') (B64.decodeLenient b64) of