yesodweb/yesod — Issue #229: yesod-auth OAuth doesn't work at all maybe
Author: darrint
Created: 2012-01-18 02:40:17+00:00
State: open

When attempting to exhange tokens to obtain an access token with the Netflix api I got a signing error. I did some debugging and found that the oauth_token_secret parameter is not passed to getAccessToken.

Possibly this is only a quirk of the Netflix api, but I doubt it.

This patch shows what I believe needs to happen but I never finished getting it working.

```
diff --git a/yesod-auth/Yesod/Auth/OAuth.hs b/yesod-auth/Yesod/Auth/OAuth.hs
index ebb1251..44931c5 100644
--- a/yesod-auth/Yesod/Auth/OAuth.hs
+++ b/yesod-auth/Yesod/Auth/OAuth.hs
@@ -53,12 +53,15 @@ authOAuth name ident reqUrl accUrl authUrl key sec = AuthPlu
gin name dispatch lo
tm <- getRouteToMaster
let oauth' = oauth { oauthCallback = Just $ encodeUtf8 $ render $ tm ur
l }
tok <- liftIO $ getTemporaryCredential oauth'
+ setSession sessionVar $ lookupTokenSecret tok
redirectText RedirectTemporary (fromString $ authorizeUrl oauth' tok)
dispatch "GET" [] = do
(verifier, oaTok) <- runInputGet $ (,)
<$> ireq textField "oauth_verifier"
<*> ireq textField "oauth_token"
- let reqTok = Credential [ ("oauth_verifier", encodeUtf8 verifier), ("oauth_token", encodeUtf8 oaTok)
+ tokenSecret <- fmap fromJust (lookupSession $ sessionVar)
+ deleteSession sessionVar
+ let reqTok = Credential [ ("oauth_verifier", encodeUtf8 verifier), ("oauth_token", encodeUtf8 oaTok), ("oauth_token_secret", encodeUtf8 tokenSecret)
]
accTok <- liftIO $ getAccessToken oauth reqTok
let crId = decodeUtf8With lenientDecode $ fromJust $ lookup (pack ident) $ unCredential accTok
@@ -70,6 +73,8 @@ authOAuth name ident reqUrl accUrl authUrl key sec = AuthPlugin name dispatch lo
let oaUrl = render $ tm $ oauthUrl name
addHtml
[QQ(shamlet)| Login with #{name} |]
+ lookupTokenSecret = bsToText . fromMaybe "" . lookup "oauth_token_secret" . unCredential
+ sessionVar = "__oauth_token_secret"

authTwitter :: YesodAuth m =>
String -- ^ Consumer Key
```