mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-01-11 19:58:28 +01:00
Replace call to error with throwIO. Fixes #2
* error would crash the server * IO exception should result in a 500
This commit is contained in:
parent
257968f067
commit
4354dc630a
@ -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"]
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user