From 5a25e5e53b7a4dc1d3782cd6d021ee458c88a17b Mon Sep 17 00:00:00 2001 From: Kazuki Okamoto Date: Sun, 28 Feb 2016 16:48:56 +0900 Subject: [PATCH 1/5] =?UTF-8?q?change=20Twitter=20ID=20screen=5Fname=20?= =?UTF-8?q?=E2=86=92=20user=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index 79ab12ac..e78ae311 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -103,7 +103,7 @@ authTwitter key secret = authOAuth , oauthConsumerSecret = secret , oauthVersion = OAuth10a }) - (mkExtractCreds "twitter" "screen_name") + (mkExtractCreds "twitter" "user_id") twitterUrl :: AuthRoute twitterUrl = oauthUrl "twitter" From d46d75455503a30cdac45c88fffab55c1825f83f Mon Sep 17 00:00:00 2001 From: Kazuki Okamoto Date: Mon, 29 Feb 2016 00:00:42 +0900 Subject: [PATCH 2/5] =?UTF-8?q?Revert=20"change=20Twitter=20ID=20screen=5F?= =?UTF-8?q?name=20=E2=86=92=20user=5Fid"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5a25e5e53b7a4dc1d3782cd6d021ee458c88a17b. --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index e78ae311..79ab12ac 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -103,7 +103,7 @@ authTwitter key secret = authOAuth , oauthConsumerSecret = secret , oauthVersion = OAuth10a }) - (mkExtractCreds "twitter" "user_id") + (mkExtractCreds "twitter" "screen_name") twitterUrl :: AuthRoute twitterUrl = oauthUrl "twitter" From 074b0c68e73a8441e60053b1c726590d6ac5f2a9 Mon Sep 17 00:00:00 2001 From: Kazuki Okamoto Date: Mon, 29 Feb 2016 04:07:42 +0900 Subject: [PATCH 3/5] add twitterId function --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index 79ab12ac..7a6c2268 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -5,6 +5,7 @@ module Yesod.Auth.OAuth , oauthUrl , authTwitter , twitterUrl + , twitterId , authTumblr , tumblrUrl , module Web.Authenticate.OAuth @@ -108,6 +109,25 @@ authTwitter key secret = authOAuth twitterUrl :: AuthRoute twitterUrl = oauthUrl "twitter" +-- | Gets Twitter ID (/user_id/) from @Creds@. +-- +-- Never use @credsIdent@ for Twitter OAuth. @credsIdent@ returns /screen_name/, which shouldn't be used for authentication. +-- /screen_name/ is text like /foo/ of /\@foo/ which is unique but __mutable__. So /screen_name/ cannot authenticate users. +-- /user_id/ is integer which is unique and __immutable__. So you should use this for authentication. +-- +-- Because of compatibility, @credsIdent@ returns /screen_name/ yet. +-- +-- Since 1.4.x.x +twitterId :: Yesod m => Creds m -> Text +twitterId creds = + let + key = "user_id" + extra = credsExtra creds + in + case lookup key extra of + Just uId -> uId + Nothing -> throw $ CredentialError ("key not found: " ++ (T.unpack key)) (Credential $ map (encodeUtf8 *** encodeUtf8) extra) + authTumblr :: YesodAuth m => ByteString -- ^ Consumer Key -> ByteString -- ^ Consumer Secret From 8a66da1f24432d50289ad6f80a75e56d78cb1ddf Mon Sep 17 00:00:00 2001 From: Kazuki Okamoto Date: Tue, 1 Mar 2016 23:21:17 +0900 Subject: [PATCH 4/5] Revert "add twitterId function" This reverts commit 074b0c68e73a8441e60053b1c726590d6ac5f2a9. --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index 7a6c2268..79ab12ac 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -5,7 +5,6 @@ module Yesod.Auth.OAuth , oauthUrl , authTwitter , twitterUrl - , twitterId , authTumblr , tumblrUrl , module Web.Authenticate.OAuth @@ -109,25 +108,6 @@ authTwitter key secret = authOAuth twitterUrl :: AuthRoute twitterUrl = oauthUrl "twitter" --- | Gets Twitter ID (/user_id/) from @Creds@. --- --- Never use @credsIdent@ for Twitter OAuth. @credsIdent@ returns /screen_name/, which shouldn't be used for authentication. --- /screen_name/ is text like /foo/ of /\@foo/ which is unique but __mutable__. So /screen_name/ cannot authenticate users. --- /user_id/ is integer which is unique and __immutable__. So you should use this for authentication. --- --- Because of compatibility, @credsIdent@ returns /screen_name/ yet. --- --- Since 1.4.x.x -twitterId :: Yesod m => Creds m -> Text -twitterId creds = - let - key = "user_id" - extra = credsExtra creds - in - case lookup key extra of - Just uId -> uId - Nothing -> throw $ CredentialError ("key not found: " ++ (T.unpack key)) (Credential $ map (encodeUtf8 *** encodeUtf8) extra) - authTumblr :: YesodAuth m => ByteString -- ^ Consumer Key -> ByteString -- ^ Consumer Secret From e1b70eb0f8c5b5d8d960f157a788c07f2b1ff18f Mon Sep 17 00:00:00 2001 From: Kazuki Okamoto Date: Wed, 2 Mar 2016 10:56:40 +0900 Subject: [PATCH 5/5] new twitter plugin --- yesod-auth-oauth/Yesod/Auth/OAuth.hs | 31 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/yesod-auth-oauth/Yesod/Auth/OAuth.hs b/yesod-auth-oauth/Yesod/Auth/OAuth.hs index 79ab12ac..13b2c9cf 100644 --- a/yesod-auth-oauth/Yesod/Auth/OAuth.hs +++ b/yesod-auth-oauth/Yesod/Auth/OAuth.hs @@ -4,6 +4,7 @@ module Yesod.Auth.OAuth ( authOAuth , oauthUrl , authTwitter + , authTwitterUsingUserId , twitterUrl , authTumblr , tumblrUrl @@ -89,11 +90,12 @@ mkExtractCreds name idName (Credential dic) = do Just crId -> return $ Creds name crId $ map (bsToText *** bsToText) dic Nothing -> throwIO $ CredentialError ("key not found: " ++ idName) (Credential dic) -authTwitter :: YesodAuth m - => ByteString -- ^ Consumer Key - -> ByteString -- ^ Consumer Secret - -> AuthPlugin m -authTwitter key secret = authOAuth +authTwitter' :: YesodAuth m + => ByteString -- ^ Consumer Key + -> ByteString -- ^ Consumer Secret + -> String + -> AuthPlugin m +authTwitter' key secret idName = authOAuth (newOAuth { oauthServerName = "twitter" , oauthRequestUri = "https://api.twitter.com/oauth/request_token" , oauthAccessTokenUri = "https://api.twitter.com/oauth/access_token" @@ -103,7 +105,24 @@ authTwitter key secret = authOAuth , oauthConsumerSecret = secret , oauthVersion = OAuth10a }) - (mkExtractCreds "twitter" "screen_name") + (mkExtractCreds "twitter" idName) + +-- | This plugin uses Twitter's /screen_name/ as ID, which shouldn't be used for authentication because it is mutable. +authTwitter :: YesodAuth m + => ByteString -- ^ Consumer Key + -> ByteString -- ^ Consumer Secret + -> AuthPlugin m +authTwitter key secret = authTwitter' key secret "screen_name" +{-# DEPRECATED authTwitter "Use authTwitterUsingUserID instead" #-} + +-- | Twitter plugin which uses Twitter's /user_id/ as ID. +-- +-- Since 1.4.x.x TODO fix version +authTwitterUsingUserId :: YesodAuth m + => ByteString -- ^ Consumer Key + -> ByteString -- ^ Consumer Secret + -> AuthPlugin m +authTwitterUsingUserId key secret = authTwitter' key secret "user_id" twitterUrl :: AuthRoute twitterUrl = oauthUrl "twitter"