http-conduit 1.1
This commit is contained in:
parent
6bff24868f
commit
5a4c6325b0
@ -40,6 +40,7 @@ import Data.Text.Lazy.Encoding (decodeUtf8With)
|
|||||||
import Data.Text.Encoding.Error (lenientDecode)
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
import Text.HTML.TagSoup (parseTags, Tag (TagOpen))
|
import Text.HTML.TagSoup (parseTags, Tag (TagOpen))
|
||||||
import Control.Applicative ((<$>), (<*>))
|
import Control.Applicative ((<$>), (<*>))
|
||||||
|
import Network.HTTP.Types (status200)
|
||||||
|
|
||||||
data Discovery = Discovery1 Text (Maybe Text)
|
data Discovery = Discovery1 Text (Maybe Text)
|
||||||
| Discovery2 Provider Identifier IdentType
|
| Discovery2 Provider Identifier IdentType
|
||||||
@ -69,14 +70,14 @@ discoverYADIS _ _ 0 = failure TooManyRedirects
|
|||||||
discoverYADIS ident mb_loc redirects = do
|
discoverYADIS ident mb_loc redirects = do
|
||||||
let uri = fromMaybe (unpack $ identifier ident) mb_loc
|
let uri = fromMaybe (unpack $ identifier ident) mb_loc
|
||||||
req <- parseUrl uri
|
req <- parseUrl uri
|
||||||
res <- liftIO $ withManager $ httpLbs req
|
res <- liftIO $ withManager $ httpLbs req { checkStatus = \_ _ -> Nothing }
|
||||||
let mloc = fmap S8.unpack
|
let mloc = fmap S8.unpack
|
||||||
$ lookup "x-xrds-location"
|
$ lookup "x-xrds-location"
|
||||||
$ map (first $ map toLower . S8.unpack . CI.original)
|
$ map (first $ map toLower . S8.unpack . CI.original)
|
||||||
$ responseHeaders res
|
$ responseHeaders res
|
||||||
let mloc' = if mloc == mb_loc then Nothing else mloc
|
let mloc' = if mloc == mb_loc then Nothing else mloc
|
||||||
case statusCode res of
|
if statusCode res == status200
|
||||||
200 ->
|
then
|
||||||
case mloc' of
|
case mloc' of
|
||||||
Just loc -> discoverYADIS ident (Just loc) (redirects - 1)
|
Just loc -> discoverYADIS ident (Just loc) (redirects - 1)
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
@ -84,7 +85,7 @@ discoverYADIS ident mb_loc redirects = do
|
|||||||
case mdoc of
|
case mdoc of
|
||||||
Just doc -> return $ parseYADIS ident doc
|
Just doc -> return $ parseYADIS ident doc
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
_ -> return Nothing
|
else return Nothing
|
||||||
|
|
||||||
|
|
||||||
-- | Parse out an OpenID endpoint, and actual identifier from a YADIS xml
|
-- | Parse out an OpenID endpoint, and actual identifier from a YADIS xml
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import Codec.Crypto.RSA (rsassa_pkcs1_v1_5_sign, ha_SHA1, PrivateKey(..))
|
|||||||
import Network.HTTP.Types (Header)
|
import Network.HTTP.Types (Header)
|
||||||
import Blaze.ByteString.Builder (toByteString)
|
import Blaze.ByteString.Builder (toByteString)
|
||||||
import Control.Monad.IO.Class (MonadIO)
|
import Control.Monad.IO.Class (MonadIO)
|
||||||
import Network.HTTP.Types (renderSimpleQuery)
|
import Network.HTTP.Types (renderSimpleQuery, status200)
|
||||||
import Data.Conduit (ResourceIO, runResourceT, ($$), ($=), Source)
|
import Data.Conduit (ResourceIO, runResourceT, ($$), ($=), Source)
|
||||||
import qualified Data.Conduit.List as CL
|
import qualified Data.Conduit.List as CL
|
||||||
import Data.Conduit.Blaze (builderToByteString)
|
import Data.Conduit.Blaze (builderToByteString)
|
||||||
@ -133,7 +133,7 @@ getTemporaryCredential' hook oa = do
|
|||||||
crd = maybe id (insert "oauth_callback") (oauthCallback oa) $ emptyCredential
|
crd = maybe id (insert "oauth_callback") (oauthCallback oa) $ emptyCredential
|
||||||
req' <- signOAuth oa crd $ hook (req { method = "POST" })
|
req' <- signOAuth oa crd $ hook (req { method = "POST" })
|
||||||
rsp <- withManager . httpLbs $ req'
|
rsp <- withManager . httpLbs $ req'
|
||||||
if statusCode rsp == 200
|
if statusCode rsp == status200
|
||||||
then do
|
then do
|
||||||
let dic = parseSimpleQuery . toStrict . responseBody $ rsp
|
let dic = parseSimpleQuery . toStrict . responseBody $ rsp
|
||||||
return $ Credential dic
|
return $ Credential dic
|
||||||
@ -170,7 +170,7 @@ getAccessToken' :: (Request IO -> Request IO) -- ^ Request Hook
|
|||||||
getAccessToken' hook oa cr = do
|
getAccessToken' hook oa cr = do
|
||||||
let req = hook (fromJust $ parseUrl $ oauthAccessTokenUri oa) { method = "POST" }
|
let req = hook (fromJust $ parseUrl $ oauthAccessTokenUri oa) { method = "POST" }
|
||||||
rsp <- withManager . httpLbs =<< signOAuth oa cr req
|
rsp <- withManager . httpLbs =<< signOAuth oa cr req
|
||||||
if statusCode rsp == 200
|
if statusCode rsp == status200
|
||||||
then do
|
then do
|
||||||
let dic = parseSimpleQuery . toStrict . responseBody $ rsp
|
let dic = parseSimpleQuery . toStrict . responseBody $ rsp
|
||||||
return $ Credential dic
|
return $ Credential dic
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import Data.Text.Lazy.Encoding (decodeUtf8With)
|
|||||||
import Data.Text.Encoding.Error (lenientDecode)
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
import Data.Text.Lazy (toStrict)
|
import Data.Text.Lazy (toStrict)
|
||||||
import Network.HTTP.Conduit
|
import Network.HTTP.Conduit
|
||||||
( parseUrl, urlEncodedBody, responseBody, httpLbsRedirect
|
( parseUrl, urlEncodedBody, responseBody, httpLbs
|
||||||
, HttpException, withManager
|
, HttpException, withManager
|
||||||
)
|
)
|
||||||
import Control.Arrow ((***), second)
|
import Control.Arrow ((***), second)
|
||||||
@ -95,7 +95,7 @@ authenticate params = do
|
|||||||
: filter (\(k, _) -> k /= "openid.mode") params
|
: filter (\(k, _) -> k /= "openid.mode") params
|
||||||
req' <- parseUrl $ unpack endpoint
|
req' <- parseUrl $ unpack endpoint
|
||||||
let req = urlEncodedBody params' req'
|
let req = urlEncodedBody params' req'
|
||||||
rsp <- liftIO $ withManager $ httpLbsRedirect req
|
rsp <- liftIO $ withManager $ httpLbs req
|
||||||
let rps = parseDirectResponse $ toStrict $ decodeUtf8With lenientDecode $ responseBody rsp
|
let rps = parseDirectResponse $ toStrict $ decodeUtf8With lenientDecode $ responseBody rsp
|
||||||
case lookup "is_valid" rps of
|
case lookup "is_valid" rps of
|
||||||
Just "true" -> return (Identifier ident, rps)
|
Just "true" -> return (Identifier ident, rps)
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import Data.Maybe
|
|||||||
import Control.Monad
|
import Control.Monad
|
||||||
import qualified Data.ByteString.Char8 as S
|
import qualified Data.ByteString.Char8 as S
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
import Control.Exception (throwIO)
|
|
||||||
import Web.Authenticate.Internal
|
import Web.Authenticate.Internal
|
||||||
import Data.Data (Data)
|
import Data.Data (Data)
|
||||||
import Data.Typeable (Typeable)
|
import Data.Typeable (Typeable)
|
||||||
@ -75,10 +74,8 @@ authenticate apiKey token = do
|
|||||||
]
|
]
|
||||||
, requestBody = RequestBodyLBS body
|
, requestBody = RequestBodyLBS body
|
||||||
}
|
}
|
||||||
res <- liftIO $ withManager $ httpLbsRedirect req
|
res <- liftIO $ withManager $ httpLbs req
|
||||||
let b = responseBody res
|
let b = responseBody res
|
||||||
unless (200 <= statusCode res && statusCode res < 300) $
|
|
||||||
liftIO $ throwIO $ StatusCodeException (statusCode res) b
|
|
||||||
o <- unResult $ parse json b
|
o <- unResult $ parse json b
|
||||||
--m <- fromMapping o
|
--m <- fromMapping o
|
||||||
let mstat = flip Data.Aeson.Types.parse o $ \v ->
|
let mstat = flip Data.Aeson.Types.parse o $ \v ->
|
||||||
|
|||||||
@ -16,7 +16,7 @@ homepage: http://github.com/yesodweb/authenticate
|
|||||||
library
|
library
|
||||||
build-depends: base >= 4 && < 5,
|
build-depends: base >= 4 && < 5,
|
||||||
aeson >= 0.5,
|
aeson >= 0.5,
|
||||||
http-conduit >= 1.0 && < 1.1,
|
http-conduit >= 1.1 && < 1.2,
|
||||||
tagsoup >= 0.12 && < 0.13,
|
tagsoup >= 0.12 && < 0.13,
|
||||||
failure >= 0.0.0 && < 0.2,
|
failure >= 0.0.0 && < 0.2,
|
||||||
transformers >= 0.1 && < 0.3,
|
transformers >= 0.1 && < 0.3,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user