diff --git a/Yesod/Auth/OAuth2.hs b/Yesod/Auth/OAuth2.hs index 3463ddc..bde70d2 100644 --- a/Yesod/Auth/OAuth2.hs +++ b/Yesod/Auth/OAuth2.hs @@ -1,4 +1,6 @@ -{-# LANGUAGE OverloadedStrings, QuasiQuotes #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} -- | -- -- Generic OAuth2 plugin for Yesod @@ -8,19 +10,31 @@ module Yesod.Auth.OAuth2 ( authOAuth2 , oauth2Url + , YesodOAuth2Exception(..) , module Network.OAuth.OAuth2 ) where +import Control.Exception.Lifted import Control.Monad.IO.Class import Data.ByteString (ByteString) import Data.Text (Text) import Data.Text.Encoding (decodeUtf8With, encodeUtf8) import Data.Text.Encoding.Error (lenientDecode) +import Data.Typeable import Network.OAuth.OAuth2 import Yesod.Auth import Yesod.Core import Yesod.Form +import qualified Data.ByteString.Lazy as BSL + +data YesodOAuth2Exception = InvalidProfileResponse + Text -- ^ Provider name + BSL.ByteString -- ^ Aeson parse error + deriving (Show, Typeable) + +instance Exception YesodOAuth2Exception + oauth2Url :: Text -> AuthRoute oauth2Url name = PluginR name ["forward"] diff --git a/Yesod/Auth/OAuth2/Learn.hs b/Yesod/Auth/OAuth2/Learn.hs index 46879ad..a26f0f7 100644 --- a/Yesod/Auth/OAuth2/Learn.hs +++ b/Yesod/Auth/OAuth2/Learn.hs @@ -13,6 +13,7 @@ module Yesod.Auth.OAuth2.Learn ) where import Control.Applicative ((<$>), (<*>)) +import Control.Exception.Lifted import Control.Monad (mzero) import Data.Aeson import Data.Text (Text) @@ -65,7 +66,7 @@ fetchLearnProfile token = do case result of Right (LearnResponse user) -> return $ toCreds user - _ -> error "Invalid response for learn profile data" + Left err -> throwIO $ InvalidProfileResponse "learn" err toCreds :: LearnUser -> Creds m toCreds user = Creds "learn" diff --git a/yesod-auth-oauth2.cabal b/yesod-auth-oauth2.cabal index 05e9a7a..1ad4f8e 100644 --- a/yesod-auth-oauth2.cabal +++ b/yesod-auth-oauth2.cabal @@ -31,6 +31,7 @@ library , yesod-form >= 1.3 && < 1.4 , transformers >= 0.2.2 && < 0.4 , hoauth2 >= 0.3.6 && < 0.4 + , lifted-base >= 0.2.2 && < 0.4 exposed-modules: Yesod.Auth.OAuth2 Yesod.Auth.OAuth2.Google