mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-04-18 08:54:12 +02:00
Extract errInvalidOAuth
This commit is contained in:
parent
07c757aaa5
commit
aa9736b80e
@ -9,7 +9,7 @@ module Yesod.Auth.OAuth2.Dispatch
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Exception.Safe (throwString, tryIO)
|
import Control.Exception.Safe (throwString, tryIO)
|
||||||
import Control.Monad (unless)
|
import Control.Monad (unless, (<=<))
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
@ -65,15 +65,12 @@ dispatchCallback name oauth2 getCreds = do
|
|||||||
where
|
where
|
||||||
-- On a Left result, log it and return an opaque permission-denied
|
-- On a Left result, log it and return an opaque permission-denied
|
||||||
denyLeft :: (MonadHandler m, MonadLogger m, Show e) => IO (Either e a) -> m a
|
denyLeft :: (MonadHandler m, MonadLogger m, Show e) => IO (Either e a) -> m a
|
||||||
denyLeft act = do
|
denyLeft = either errInvalidOAuth pure <=< liftIO
|
||||||
result <- liftIO act
|
|
||||||
either
|
errInvalidOAuth :: (MonadHandler m, MonadLogger m, Show e) => e -> m a
|
||||||
(\err -> do
|
errInvalidOAuth err = do
|
||||||
$(logError) $ T.pack $ "OAuth2 error: " <> show err
|
$(logError) $ T.pack $ "OAuth2 error: " <> show err
|
||||||
permissionDenied "Invalid OAuth2 authentication attempt"
|
permissionDenied "Invalid OAuth2 authentication attempt"
|
||||||
)
|
|
||||||
return
|
|
||||||
result
|
|
||||||
|
|
||||||
withCallbackAndState :: Text -> OAuth2 -> Text -> AuthHandler m OAuth2
|
withCallbackAndState :: Text -> OAuth2 -> Text -> AuthHandler m OAuth2
|
||||||
withCallbackAndState name oauth2 csrf = do
|
withCallbackAndState name oauth2 csrf = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user