Version upgrade (hoauth2 0.4.1).

This commit is contained in:
Kayo Phoenix 2014-08-13 11:02:46 +06:00
parent 961ec96a0b
commit d9a41130b0
3 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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