diff --git a/Yesod/Auth/OAuth2.hs b/Yesod/Auth/OAuth2.hs index cf350fe..72fcd2a 100644 --- a/Yesod/Auth/OAuth2.hs +++ b/Yesod/Auth/OAuth2.hs @@ -22,6 +22,7 @@ import Data.Text.Encoding (decodeUtf8With, encodeUtf8) import Data.Text.Encoding.Error (lenientDecode) import Data.Typeable import Network.OAuth.OAuth2 +import Network.HTTP.Conduit(Manager) import Yesod.Auth import Yesod.Core import Yesod.Form @@ -41,7 +42,7 @@ oauth2Url name = PluginR name ["forward"] authOAuth2 :: YesodAuth m => Text -- ^ Service name -> OAuth2 -- ^ Service details - -> (AccessToken -> IO (Creds m)) + -> (Manager -> AccessToken -> IO (Creds m)) -- ^ This function defines how to take an @'AccessToken'@ and -- retrieve additional information about the user, to be -- set in the session as @'Creds'@. Usually this means a @@ -64,11 +65,12 @@ authOAuth2 name oauth getCreds = AuthPlugin name dispatch login dispatch "GET" ["callback"] = do code <- lift $ runInputGet $ ireq textField "code" oauth' <- withCallback - result <- liftIO $ fetchAccessToken oauth' (encodeUtf8 code) + master <- lift getYesod + result <- liftIO $ fetchAccessToken (authHttpManager master) oauth' (encodeUtf8 code) case result of Left _ -> permissionDenied "Unable to retreive OAuth2 token" Right token -> do - creds <- liftIO $ getCreds token + creds <- liftIO $ getCreds (authHttpManager master) token lift $ setCredsRedirect creds dispatch _ _ = notFound diff --git a/Yesod/Auth/OAuth2/Learn.hs b/Yesod/Auth/OAuth2/Learn.hs index a26f0f7..eca9040 100644 --- a/Yesod/Auth/OAuth2/Learn.hs +++ b/Yesod/Auth/OAuth2/Learn.hs @@ -20,6 +20,7 @@ import Data.Text (Text) import Data.Text.Encoding (encodeUtf8) import Yesod.Auth import Yesod.Auth.OAuth2 +import Network.HTTP.Conduit(Manager) import qualified Data.Text as T data LearnUser = LearnUser @@ -60,10 +61,10 @@ oauth2Learn clientId clientSecret = authOAuth2 "learn" }) fetchLearnProfile -fetchLearnProfile :: AccessToken -> IO (Creds m) -fetchLearnProfile token = do - result <- authGetJSON token "http://learn.thoughtbot.com/api/v1/me.json" - +fetchLearnProfile :: Manager -> AccessToken -> IO (Creds m) +fetchLearnProfile manager token = do + result <- authGetJSON manager token "http://learn.thoughtbot.com/api/v1/me.json" + case result of Right (LearnResponse user) -> return $ toCreds user Left err -> throwIO $ InvalidProfileResponse "learn" err diff --git a/yesod-auth-oauth2.cabal b/yesod-auth-oauth2.cabal index 0364de1..4e4d4f8 100644 --- a/yesod-auth-oauth2.cabal +++ b/yesod-auth-oauth2.cabal @@ -30,7 +30,7 @@ library , text >= 0.7 && < 2.0 , yesod-form >= 1.3 && < 1.4 , transformers >= 0.2.2 && < 0.4 - , hoauth2 >= 0.3.6 && < 0.4 + , hoauth2 >= 0.4.1 && < 0.5 , lifted-base >= 0.2 && < 0.4 exposed-modules: Yesod.Auth.OAuth2