From df89f0c31232138a262f5f305789227eada622d0 Mon Sep 17 00:00:00 2001 From: Hiromi Ishii Date: Fri, 2 Mar 2012 16:28:21 +0900 Subject: [PATCH] (maybe) resolved oauth-1.0 problem --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 31 +++++++++++++++++-------- yesod-auth-oauth/yesod-auth-oauth.cabal | 4 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index 8d2598de..615cdb15 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -48,19 +48,29 @@ authOAuth oauth mkCreds = AuthPlugin name dispatch login setSession oauthSessionName $ lookupTokenSecret tok redirect $ authorizeUrl oauth' tok dispatch "GET" [] = do - (verifier, oaTok) <- runInputGet $ (,) - <$> ireq textField "oauth_verifier" - <*> ireq textField "oauth_token" - tokSec <- fromJust <$> lookupSession oauthSessionName - deleteSession oauthSessionName - let reqTok = Credential [ ("oauth_verifier", encodeUtf8 verifier) + reqTok <- + if oauthVersion oauth == OAuth10 + then do + oaTok <- runInputGet $ ireq textField "oauth_token" + tokSec <- fromJust <$> lookupSession oauthSessionName + deleteSession oauthSessionName + return $ Credential [ ("oauth_token", encodeUtf8 oaTok) + , ("oauth_token_secret", encodeUtf8 tokSec) + ] + else do + (verifier, oaTok) <- + runInputGet $ (,) <$> ireq textField "oauth_verifier" + <*> ireq textField "oauth_token" + tokSec <- fromJust <$> lookupSession oauthSessionName + 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) - creds <- resourceLiftBase $ mkCreds accTok - setCreds True creds + master <- getYesod + accTok <- lift $ getAccessToken oauth reqTok (authHttpManager master) + creds <- resourceLiftBase $ mkCreds accTok + setCreds True creds dispatch _ _ = notFound login tm = do render <- lift getUrlRender @@ -80,6 +90,7 @@ authTwitter key secret = authOAuth , oauthSignatureMethod = HMACSHA1 , oauthConsumerKey = key , oauthConsumerSecret = secret + , oauthVersion = OAuth10a }) extractCreds where diff --git a/yesod-auth-oauth/yesod-auth-oauth.cabal b/yesod-auth-oauth/yesod-auth-oauth.cabal index f86efd85..aa50df9f 100644 --- a/yesod-auth-oauth/yesod-auth-oauth.cabal +++ b/yesod-auth-oauth/yesod-auth-oauth.cabal @@ -1,5 +1,5 @@ name: yesod-auth-oauth -version: 0.8.0 +version: 0.8.1 license: BSD3 license-file: LICENSE author: Hiromi Ishii @@ -21,7 +21,7 @@ library cpp-options: -DGHC7 else build-depends: base >= 4 && < 4.3 - build-depends: authenticate-oauth >= 1.0 && < 1.1 + build-depends: authenticate-oauth >= 1.1 && < 1.2 , bytestring >= 0.9.1.4 && < 0.10 , yesod-core >= 0.10 && < 0.11 , yesod-auth >= 0.8 && < 0.9