(maybe) resolved oauth-1.0 problem

This commit is contained in:
Hiromi Ishii 2012-03-02 16:28:21 +09:00
parent 30f6348e56
commit df89f0c312
2 changed files with 23 additions and 12 deletions

View File

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

View File

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