mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-03-03 03:44:35 +01:00
Rename qualified import
This commit is contained in:
parent
38c2362a98
commit
79cd0161d3
@ -62,13 +62,14 @@ module Yesod.Auth.OAuth2.Prelude
|
|||||||
-- * Deprecated, until everything's moved over to @'authGetProfile'@
|
-- * Deprecated, until everything's moved over to @'authGetProfile'@
|
||||||
, authGetJSON
|
, authGetJSON
|
||||||
, fromProfileURL
|
, fromProfileURL
|
||||||
|
, maybeExtra
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString.Lazy as BSL
|
import qualified Data.ByteString.Lazy as BL
|
||||||
import qualified Data.ByteString.Lazy.Char8 as BSL8
|
import qualified Data.ByteString.Lazy.Char8 as BL8
|
||||||
import Data.Semigroup ((<>))
|
import Data.Semigroup ((<>))
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
@ -86,7 +87,7 @@ import Yesod.Auth.OAuth2
|
|||||||
--
|
--
|
||||||
-- Deprecated. Eventually, we'll return @Either@s all the way up.
|
-- Deprecated. Eventually, we'll return @Either@s all the way up.
|
||||||
--
|
--
|
||||||
data YesodOAuth2Exception = InvalidProfileResponse Text BSL.ByteString
|
data YesodOAuth2Exception = InvalidProfileResponse Text BL.ByteString
|
||||||
deriving (Show, Typeable)
|
deriving (Show, Typeable)
|
||||||
instance Exception YesodOAuth2Exception
|
instance Exception YesodOAuth2Exception
|
||||||
|
|
||||||
@ -106,22 +107,22 @@ authGetProfile
|
|||||||
-> Manager
|
-> Manager
|
||||||
-> OAuth2Token
|
-> OAuth2Token
|
||||||
-> URI
|
-> URI
|
||||||
-> IO (a, BSL.ByteString)
|
-> IO (a, BL.ByteString)
|
||||||
authGetProfile name manager token url = do
|
authGetProfile name manager token url = do
|
||||||
resp <- fromAuthGet name =<< authGetBS manager (accessToken token) url
|
resp <- fromAuthGet name =<< authGetBS manager (accessToken token) url
|
||||||
decoded <- fromAuthJSON name resp
|
decoded <- fromAuthJSON name resp
|
||||||
pure (decoded, resp)
|
pure (decoded, resp)
|
||||||
|
|
||||||
-- | Throws a @Left@ result as an @'InvalidProfileResponse'@
|
-- | Throws a @Left@ result as an @'InvalidProfileResponse'@
|
||||||
fromAuthGet :: Text -> Either (OAuth2Error Value) BSL.ByteString -> IO BSL.ByteString
|
fromAuthGet :: Text -> Either (OAuth2Error Value) BL.ByteString -> IO BL.ByteString
|
||||||
fromAuthGet _ (Right bs) = pure bs -- nice
|
fromAuthGet _ (Right bs) = pure bs -- nice
|
||||||
fromAuthGet name (Left err) = throwIO $ invalidProfileResponse name err
|
fromAuthGet name (Left err) = throwIO $ invalidProfileResponse name err
|
||||||
|
|
||||||
-- | Throws a decoding error as an @'InvalidProfileResponse'@
|
-- | Throws a decoding error as an @'InvalidProfileResponse'@
|
||||||
fromAuthJSON :: FromJSON a => Text -> BSL.ByteString -> IO a
|
fromAuthJSON :: FromJSON a => Text -> BL.ByteString -> IO a
|
||||||
fromAuthJSON name =
|
fromAuthJSON name =
|
||||||
-- FIXME: unique exception constructors
|
-- FIXME: unique exception constructors
|
||||||
either (throwIO . InvalidProfileResponse name . BSL8.pack) pure . eitherDecode
|
either (throwIO . InvalidProfileResponse name . BL8.pack) pure . eitherDecode
|
||||||
|
|
||||||
-- | Construct an @'InvalidProfileResponse'@ exception from an @'OAuth2Error'@
|
-- | Construct an @'InvalidProfileResponse'@ exception from an @'OAuth2Error'@
|
||||||
--
|
--
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user