From a897502679333340979b4c291f56f8b4eda5fc68 Mon Sep 17 00:00:00 2001 From: notogawa Date: Sat, 18 May 2013 23:01:15 +0900 Subject: [PATCH] caught up with yesod 1.2 --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 32 +++++++++++-------------- yesod-auth-oauth/yesod-auth-oauth.cabal | 6 ++--- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index a2929aff..fa7f1c76 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -4,8 +4,8 @@ module Yesod.Auth.OAuth , oauthUrl , authTwitter , twitterUrl - , authTumblr - , tumblrUrl + , authTumblr + , tumblrUrl , module Web.Authenticate.OAuth ) where import Control.Applicative ((<$>), (<*>)) @@ -22,8 +22,7 @@ import Data.Typeable import Web.Authenticate.OAuth import Yesod.Auth import Yesod.Form -import Yesod.Handler -import Yesod.Widget +import Yesod.Core data YesodOAuthException = CredentialError String Credential | SessionError String @@ -40,26 +39,25 @@ authOAuth :: YesodAuth m -> AuthPlugin m authOAuth oauth mkCreds = AuthPlugin name dispatch login where - getOAuthSession = maybe (throwIO $ SessionError "") return =<< lookupSession oauthSessionName name = T.pack $ oauthServerName oauth url = PluginR name [] lookupTokenSecret = bsToText . fromMaybe "" . lookup "oauth_token_secret" . unCredential oauthSessionName = "__oauth_token_secret" dispatch "GET" ["forward"] = do - render <- getUrlRender - tm <- getRouteToMaster + render <- lift getUrlRender + tm <- getRouteToParent let oauth' = oauth { oauthCallback = Just $ encodeUtf8 $ render $ tm url } - master <- getYesod + master <- lift getYesod tok <- lift $ getTemporaryCredential oauth' (authHttpManager master) setSession oauthSessionName $ lookupTokenSecret tok redirect $ authorizeUrl oauth' tok - dispatch "GET" [] = do + dispatch "GET" [] = lift $ do + Just tokSec <- lookupSession oauthSessionName + deleteSession oauthSessionName reqTok <- if oauthVersion oauth == OAuth10 then do oaTok <- runInputGet $ ireq textField "oauth_token" - tokSec <- getOAuthSession - deleteSession oauthSessionName return $ Credential [ ("oauth_token", encodeUtf8 oaTok) , ("oauth_token_secret", encodeUtf8 tokSec) ] @@ -67,19 +65,17 @@ authOAuth oauth mkCreds = AuthPlugin name dispatch login (verifier, oaTok) <- runInputGet $ (,) <$> ireq textField "oauth_verifier" <*> ireq textField "oauth_token" - tokSec <- getOAuthSession - deleteSession oauthSessionName return $ Credential [ ("oauth_verifier", encodeUtf8 verifier) , ("oauth_token", encodeUtf8 oaTok) , ("oauth_token_secret", encodeUtf8 tokSec) ] master <- getYesod - accTok <- lift $ getAccessToken oauth reqTok (authHttpManager master) + accTok <- getAccessToken oauth reqTok (authHttpManager master) creds <- liftIO $ mkCreds accTok setCreds True creds dispatch _ _ = notFound login tm = do - render <- lift getUrlRender + render <- getUrlRender let oaUrl = render $ tm $ oauthUrl name [whamlet| Login via #{name} |] @@ -96,9 +92,9 @@ authTwitter :: YesodAuth m -> AuthPlugin m authTwitter key secret = authOAuth (newOAuth { oauthServerName = "twitter" - , oauthRequestUri = "http://twitter.com/oauth/request_token" - , oauthAccessTokenUri = "http://api.twitter.com/oauth/access_token" - , oauthAuthorizeUri = "http://api.twitter.com/oauth/authorize" + , oauthRequestUri = "https://api.twitter.com/oauth/request_token" + , oauthAccessTokenUri = "https://api.twitter.com/oauth/access_token" + , oauthAuthorizeUri = "https://api.twitter.com/oauth/authorize" , oauthSignatureMethod = HMACSHA1 , oauthConsumerKey = key , oauthConsumerSecret = secret diff --git a/yesod-auth-oauth/yesod-auth-oauth.cabal b/yesod-auth-oauth/yesod-auth-oauth.cabal index 556aa6e0..30aa44be 100644 --- a/yesod-auth-oauth/yesod-auth-oauth.cabal +++ b/yesod-auth-oauth/yesod-auth-oauth.cabal @@ -22,10 +22,10 @@ library build-depends: base >= 4 && < 4.3 build-depends: authenticate-oauth >= 1.4 && < 1.5 , bytestring >= 0.9.1.4 - , yesod-core >= 1.1 && < 1.2 - , yesod-auth >= 1.1 && < 1.2 + , yesod-core >= 1.2 && < 1.3 + , yesod-auth >= 1.2 && < 1.3 , text >= 0.7 && < 0.12 - , yesod-form >= 1.1 && < 1.3 + , yesod-form >= 1.3 && < 1.4 , transformers >= 0.2.2 && < 0.4 , lifted-base >= 0.2 && < 0.3 exposed-modules: Yesod.Auth.OAuth