on develop help sign in
Exposing additional credentials mechanisms
commite2744089ac2e18fb1a612502910c0551f6a9eff5 authorBrendan Hay <brendan.g.hay@gmail.com> dateMon 26 Oct 2015, 13:13 (11 years ago) parent3adb34d
2 files changed+34−19
gogol/src/Network/Google/Auth.hs+34−12 gogol/src/Network/Google/Env.hs−7
gogol/src/Network/Google/Auth.hs+34−12
@@ -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.
gogol/src/Network/Google/Env.hs−7
@@ -119,10 +119,3 @@ newEnvWith :: (MonadIO m, MonadCatch m)
119119 -> Manager
120120 -> m Env
121121newEnvWith c ss l m = Env l mempty m <$> getAuth c ss l m
122−
123−-- Maybe make it so scope is a part of service, configurable?
124−-- - needs to be per service .. but the initial authorise, what?
125−-- - investigate how the credentials are cached by oauth2client,
126−-- is it storing multiple per service you're using?
127−-- this would mean the initial refresh is invalid, since the
128−-- scope is wrong.