yesod-auth-oauth 0.4.1 → 0.8.0
raw patch · 7 files changed
+165/−178 lines, 7 filesdep +conduitdep +textdep −authenticatedep −http-enumeratordep −transformersdep ~authenticate-oauthdep ~basedep ~bytestringsetup-changed
Dependencies added: conduit, text
Dependencies removed: authenticate, http-enumerator, transformers, utf8-string
Dependency ranges changed: authenticate-oauth, base, bytestring, hamlet, yesod-auth, yesod-core, yesod-form
Files
- LICENSE +18/−23
- Setup.hs +0/−2
- Setup.lhs +8/−0
- Yesod/Auth/OAuth.hs +94/−0
- Yesod/Helpers/Auth/OAuth.hs +0/−86
- include/qq.h +10/−0
- yesod-auth-oauth.cabal +35/−67
LICENSE view
@@ -1,30 +1,25 @@-Copyright (c)2011, Hiromi ISHII+The following license covers this documentation, and the source code, except+where otherwise indicated. -All rights reserved.+Copyright 2010, Michael Snoyman. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.-- * Redistributions in binary form must reproduce the above- copyright notice, this list of conditions and the following- disclaimer in the documentation and/or other materials provided- with the distribution.+* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer. - * Neither the name of Hiromi ISHII nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission.+* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
+ Setup.lhs view
@@ -0,0 +1,8 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple+> import System.Cmd (system)++> main :: IO ()+> main = defaultMain
+ Yesod/Auth/OAuth.hs view
@@ -0,0 +1,94 @@+{-# LANGUAGE CPP, QuasiQuotes, OverloadedStrings #-}+{-# OPTIONS_GHC -fwarn-unused-imports #-}+module Yesod.Auth.OAuth+ ( authOAuth+ , oauthUrl+ , authTwitter+ , twitterUrl+ , module Web.Authenticate.OAuth+ ) where++#include "qq.h"++import Yesod.Auth+import Yesod.Form+import Yesod.Handler+import Yesod.Widget+import Text.Hamlet (shamlet)+import Web.Authenticate.OAuth+import Data.Maybe+import Control.Arrow ((***))+import Data.Text (Text)+import qualified Data.Text as T+import Data.Text.Encoding (encodeUtf8, decodeUtf8With)+import Data.Text.Encoding.Error (lenientDecode)+import Data.ByteString (ByteString)+import Control.Applicative ((<$>), (<*>))+import Data.Conduit++oauthUrl :: Text -> AuthRoute+oauthUrl name = PluginR name ["forward"]++authOAuth :: YesodAuth m+ => OAuth -- ^ 'OAuth' data-type for signing.+ -> (Credential -> IO (Creds m)) -- ^ How to extract ident. + -> AuthPlugin m+authOAuth oauth mkCreds = AuthPlugin name dispatch login+ where+ 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+ let oauth' = oauth { oauthCallback = Just $ encodeUtf8 $ render $ tm url }+ master <- getYesod+ tok <- lift $ getTemporaryCredential oauth' (authHttpManager master)+ 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)+ , ("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+ dispatch _ _ = notFound+ login tm = do+ render <- lift getUrlRender+ let oaUrl = render $ tm $ oauthUrl name+ addHtml+ [QQ(shamlet)| <a href=#{oaUrl}>Login via #{name} |]++authTwitter :: YesodAuth m+ => ByteString -- ^ Consumer Key+ -> ByteString -- ^ Consumer Secret+ -> AuthPlugin m+authTwitter key secret = authOAuth+ (newOAuth { oauthServerName = "twitter"+ , 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+ })+ extractCreds+ where+ extractCreds (Credential dic) = do+ let crId = decodeUtf8With lenientDecode $ fromJust $ lookup "screen_name" dic+ return $ Creds "twitter" crId $ map (bsToText *** bsToText ) dic++twitterUrl :: AuthRoute+twitterUrl = oauthUrl "twitter"++bsToText :: ByteString -> Text+bsToText = decodeUtf8With lenientDecode
− Yesod/Helpers/Auth/OAuth.hs
@@ -1,86 +0,0 @@-{-# LANGUAGE CPP, QuasiQuotes, OverloadedStrings #-}-module Yesod.Helpers.Auth.OAuth- ( authOAuth- , oauthUrl- , authTwitter- , twitterUrl- ) where-import Yesod.Helpers.Auth-import Yesod.Form-import Yesod.Handler-import Yesod.Widget-import Text.Hamlet (hamlet)-import Web.Authenticate.OAuth-import Data.Maybe-import Data.String-import Network.HTTP.Enumerator-import Data.ByteString.Char8 (unpack, pack)-import Control.Arrow ((***))-import Control.Monad-import Control.Monad.IO.Class (liftIO)-import Control.Monad.Trans.Class (lift)--oauthUrl :: String -> AuthRoute-oauthUrl name = PluginR name ["forward"]--authOAuth :: YesodAuth m =>- String -- ^ Service Name- -> String -- ^ OAuth Parameter Name to use for identify- -> String -- ^ Request URL- -> String -- ^ Access Token URL- -> String -- ^ Authorize URL- -> String -- ^ Consumer Key- -> String -- ^ Consumer Secret- -> AuthPlugin m-authOAuth name ident reqUrl accUrl authUrl key sec = AuthPlugin name dispatch login- where- url = PluginR name []- oauth = OAuth { oauthServerName = name, oauthRequestUri = reqUrl- , oauthAccessTokenUri = accUrl, oauthAuthorizeUri = authUrl- , oauthSignatureMethod = HMACSHA1- , oauthConsumerKey = fromString key, oauthConsumerSecret = fromString sec- , oauthCallback = Nothing- }- dispatch "GET" ["forward"] = do- render <- getUrlRender- tm <- getRouteToMaster- let oauth' = oauth { oauthCallback = Just $ fromString $ render $ tm url }- tok <- liftIO $ getTemporaryCredential oauth'- redirectString RedirectTemporary (fromString $ authorizeUrl oauth' tok)- dispatch "GET" [] = do- render <- getUrlRender- tm <- getRouteToMaster- let callback = render $ tm url- verifier <- runFormGet' $ stringInput "oauth_verifier"- oaTok <- runFormGet' $ stringInput "oauth_token"- let reqTok = Credential [ ("oauth_verifier", pack verifier), ("oauth_token", pack oaTok)- ] - accTok <- liftIO $ getTokenCredential oauth reqTok- let crId = unpack $ fromJust $ lookup (pack ident) $ unCredential accTok- creds = Creds name crId $ map (unpack *** unpack) $ unCredential accTok- setCreds True creds- dispatch _ _ = notFound- login tm = do- render <- lift getUrlRender- let oaUrl = render $ tm $ oauthUrl name- addHtml-#if GHC7- [hamlet|-#else- [$hamlet|-#endif- <a href=#{oaUrl}>Login with #{name}- |]--authTwitter :: YesodAuth m =>- String -- ^ Consumer Key- -> String -- ^ Consumer Secret- -> AuthPlugin m-authTwitter = authOAuth "twitter"- "screen_name"- "http://twitter.com/oauth/request_token"- "http://twitter.com/oauth/access_token"- "http://twitter.com/oauth/authorize"--twitterUrl :: AuthRoute-twitterUrl = oauthUrl "twitter"
+ include/qq.h view
@@ -0,0 +1,10 @@++-- CPP macro which choses which quasyquotes syntax to use depending+-- on GHC version.+--+-- QQ stands for quasyquote.+#if GHC7+# define QQ(x) x+#else+# define QQ(x) $x+#endif
yesod-auth-oauth.cabal view
@@ -1,71 +1,39 @@--- yesod-auth-oauth.cabal auto-generated by cabal init. For additional--- options, see--- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.--- The name of the package.-Name: yesod-auth-oauth---- The package version. See the Haskell package versioning policy--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for--- standards guiding when and how versions should be incremented.-Version: 0.4.1---- A short (one-line) description of the package.-Synopsis: OAuth wrapper for yesod-auth---- A longer description of the package.-Description: OAuth client interface for yesod-auth.---- The license under which the package is released.-License: BSD3---- The file containing the license text.-License-file: LICENSE---- The package author(s).-Author: Hiromi ISHII---- An email address to which users can send suggestions, bug reports,--- and patches.-Maintainer: konn.jinro_at_gmail.com---- A copyright notice.--- Copyright: --Category: Web--Build-type: Simple---- Extra files to be distributed with the package, such as examples or--- a README.--- Extra-source-files: ---- Constraint on the version of Cabal needed to build this package.-Cabal-version: >=1.2-+name: yesod-auth-oauth+version: 0.8.0+license: BSD3+license-file: LICENSE+author: Hiromi Ishii+maintainer: Hiromi Ishii+synopsis: OAuth Authentication for Yesod.+category: Web, Yesod+stability: Stable+cabal-version: >= 1.6.0+build-type: Simple+homepage: http://www.yesodweb.com/+extra-source-files: include/qq.h+description: Authentication for Yesod. -flag oauth-not-supported- Description: use authenticate-oauth instead of authenticate- Default: True+flag ghc7 -Library- -- Modules exported by the library.- Exposed-modules: Yesod.Helpers.Auth.OAuth- - -- Packages needed in order to build this package.- Build-depends: base >= 4 && < 5, yesod-auth >= 0.3 && < 0.4,- bytestring >= 0.9 && < 1.0, http-enumerator >= 0.3 && <0.4,- utf8-string >= 0.3 && < 0.4, hamlet >= 0.7 && < 0.8,- yesod-core >= 0.7 && < 0.8, yesod-form >= 0.0 && < 0.1,- transformers >= 0.2 && < 0.3+library+ if flag(ghc7)+ build-depends: base >= 4.3 && < 5+ cpp-options: -DGHC7+ else+ build-depends: base >= 4 && < 4.3+ build-depends: authenticate-oauth >= 1.0 && < 1.1+ , bytestring >= 0.9.1.4 && < 0.10+ , yesod-core >= 0.10 && < 0.11+ , yesod-auth >= 0.8 && < 0.9+ , text >= 0.7 && < 0.12+ , hamlet >= 0.10 && < 0.11+ , conduit >= 0.2 && < 0.3+ , yesod-form >= 0.4 && < 0.5 - if flag(oauth-not-supported)- Build-depends: authenticate-oauth >= 0.1 && < 0.2- else- Build-depends: authenticate >= 0.8.1 && < 0.9+ exposed-modules: Yesod.Auth.OAuth+ ghc-options: -Wall+ include-dirs: include - -- Modules not exported by this package.- -- Other-modules: - - -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.- -- Build-tools: - +source-repository head+ type: git+ location: https://github.com/yesodweb/yesod