@@ -23,7 +23,7 @@ module Network.Google.Auth
2323 -- * Authentication
2424 -- ** Retrieving Authentication
2525 getAuth
26− , Credentials (..)
26+ , Credentials (..)
2727 , Auth
2828
2929 -- ** Authorising Requests
@@ -46,15 +46,23 @@ module Network.Google.Auth
4646 , fromFile
4747 , fromFilePath
4848
49+ -- *** Authorised User
50+ , AuthorisedUser (..)
51+ , fromAuthorisedUser
52+
53+ -- *** Service Account
54+ , ServiceAccount (..)
55+ , fromServiceAccount
56+
4957 -- ** Handling Errors
50− , AsAuthError (..)
51− , AuthError (..)
58+ , AsAuthError (..)
59+ , AuthError (..)
5260
5361 -- ** Re-exported Types
54− , OAuthScope (..)
55− , OAuthToken (..)
56− , ServiceId (..)
57− , ClientId (..)
62+ , OAuthScope (..)
63+ , OAuthToken (..)
64+ , ServiceId (..)
65+ , ClientId (..)
5866 ) where
5967
6068import Control.Applicative
@@ -278,11 +286,25 @@ fromFilePath ss f l m = do
278286 e <- liftIO (LBS.readFile f) >>=
279287 either (throwM . InvalidFileError f) pure . parseLBS
280288 case e of
281− ParsedUser u -> refresh u l m >>= fmap AuthUser . liftIO . newMVar
282− -- Add a check to ensure scopes isn't empty for service_account here.
283− ParsedService a -> do
284− let s = a { _serviceScope = ss }
285− refresh s l m >>= fmap AuthSign . liftIO . newMVar
289+ ParsedUser u -> fromAuthorisedUser u l m
290+ ParsedService a -> fromServiceAccount (a { _serviceScope = ss }) l m
291+
292+fromAuthorisedUser :: (MonadIO m, MonadCatch m)
293+ => AuthorisedUser
294+ -> Logger
295+ -> Manager
296+ -> m Auth
297+fromAuthorisedUser u l m =
298+ refresh u l m >>= fmap AuthUser . liftIO . newMVar
299+
300+fromServiceAccount :: (MonadIO m, MonadCatch m)
301+ => ServiceAccount
302+ -> Logger
303+ -> Manager
304+ -> m Auth
305+fromServiceAccount s l m =
306+ -- Add a check to ensure scopes aren't empty.
307+ refresh s l m >>= fmap AuthSign . liftIO . newMVar
286308
287309-- | Lookup the @GOOGLE_APPLICATION_CREDENTIALS@ environment variable for the
288310-- default application credentials filepath.