From 342cabd95b5c0223156605e8b98920b565a426d7 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 28 Jul 2014 06:35:00 -0400 Subject: [PATCH] Update to hauth2 0.4.* --- Yesod/Auth/OAuth2.hs | 7 +++++-- Yesod/Auth/OAuth2/Learn.hs | 5 ++++- yesod-auth-oauth2.cabal | 9 +++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Yesod/Auth/OAuth2.hs b/Yesod/Auth/OAuth2.hs index bde70d2..b3476bb 100644 --- a/Yesod/Auth/OAuth2.hs +++ b/Yesod/Auth/OAuth2.hs @@ -22,6 +22,8 @@ import Data.Text.Encoding (decodeUtf8With, encodeUtf8) import Data.Text.Encoding.Error (lenientDecode) import Data.Typeable import Network.OAuth.OAuth2 +import Network.HTTP.Client (newManager) +import Network.HTTP.Client.TLS (tlsManagerSettings) import Yesod.Auth import Yesod.Core import Yesod.Form @@ -62,14 +64,15 @@ authOAuth2 name oauth getCreds = AuthPlugin name dispatch login lift $ redirect authUrl dispatch "GET" ["callback"] = do + manager <- liftIO $ newManager tlsManagerSettings code <- lift $ runInputGet $ ireq textField "code" oauth' <- withCallback - result <- liftIO $ fetchAccessToken oauth' (encodeUtf8 code) + result <- liftIO $ fetchAccessToken manager oauth' (encodeUtf8 code) case result of Left _ -> permissionDenied "Unable to retreive OAuth2 token" Right token -> do creds <- liftIO $ getCreds token - lift $ setCreds True creds + lift $ setCredsRedirect creds dispatch _ _ = notFound diff --git a/Yesod/Auth/OAuth2/Learn.hs b/Yesod/Auth/OAuth2/Learn.hs index a26f0f7..c3c6d27 100644 --- a/Yesod/Auth/OAuth2/Learn.hs +++ b/Yesod/Auth/OAuth2/Learn.hs @@ -20,6 +20,8 @@ import Data.Text (Text) import Data.Text.Encoding (encodeUtf8) import Yesod.Auth import Yesod.Auth.OAuth2 +import Network.HTTP.Client (newManager) +import Network.HTTP.Client.TLS (tlsManagerSettings) import qualified Data.Text as T data LearnUser = LearnUser @@ -62,7 +64,8 @@ oauth2Learn clientId clientSecret = authOAuth2 "learn" fetchLearnProfile :: AccessToken -> IO (Creds m) fetchLearnProfile token = do - result <- authGetJSON token "http://learn.thoughtbot.com/api/v1/me.json" + manager <- newManager tlsManagerSettings + result <- authGetJSON manager token "http://learn.thoughtbot.com/api/v1/me.json" case result of Right (LearnResponse user) -> return $ toCreds user diff --git a/yesod-auth-oauth2.cabal b/yesod-auth-oauth2.cabal index 55bfd9d..0cb4b55 100644 --- a/yesod-auth-oauth2.cabal +++ b/yesod-auth-oauth2.cabal @@ -26,13 +26,14 @@ library , http-types >= 0.8 && < 0.9 , aeson >= 0.6 && < 0.8 , yesod-core >= 1.2 && < 1.3 - , yesod-auth >= 1.2 && < 1.3 + , yesod-auth >= 1.3 && < 1.4 , text >= 0.7 && < 2.0 , yesod-form >= 1.3 && < 1.4 - , transformers >= 0.2.2 && < 0.4 - , hoauth2 >= 0.3.6 && < 0.4 + , transformers >= 0.4 && < 0.5 + , hoauth2 >= 0.4 && < 0.5 , lifted-base >= 0.2 && < 0.4 - + , http-client >= 0.3 && < 0.4 + , http-client-tls >= 0.2 && < 0.3 exposed-modules: Yesod.Auth.OAuth2 Yesod.Auth.OAuth2.Google Yesod.Auth.OAuth2.Learn