-
-authCredentialP :: Parser AuthCredential
-authCredentialP = allowEOF $!
- do string "Basic"
- many1 lws
- b64 <- many1
- $ satisfy (\ c -> (c >= 'a' && c <= 'z') ||
- (c >= 'A' && c <= 'Z') ||
- (c >= '0' && c <= '9') ||
- c == '+' ||
- c == '/' ||
- c == '=')
- let decoded = map (toEnum . fromEnum) (fromJust $ B64.decode b64)
- case break (== ':') decoded of
- (uid, ':' : password)
- -> return (BasicAuthCredential uid password)
- _ -> failP
+authCredentialP ∷ Parser AuthCredential
+authCredentialP
+ = try $
+ do _ ← string "Basic"
+ skipMany1 lws
+ b64 ← takeWhile1 base64
+ case C8.break (≡ ':') (B64.decodeLenient b64) of
+ (user, cPassword)
+ | C8.null cPassword
+ → fail "no colons in the basic auth credential"
+ | otherwise
+ → let u = fromJust $ A.fromByteString user
+ p = fromJust $ A.fromByteString (C8.tail cPassword)
+ in
+ return (BasicAuthCredential u p)
+ where
+ base64 ∷ Char → Bool
+ base64 = inClass "a-zA-Z0-9+/="