on develop help sign in
Merge pull request #39 from feumilieu/fixes.01
4db4da0Brendan Hay
gogol/src/Network/Google/Auth/InstalledApplication.hs+15−13
@@ -1,4 +1,6 @@
1+{-# LANGUAGE KindSignatures #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE DataKinds #-}
2
4
3-- |
5-- |
4-- Module : Network.Google.Auth.InstalledApplication
6-- Module : Network.Google.Auth.InstalledApplication
@@ -32,6 +34,7 @@ module Network.Google.Auth.InstalledApplication
32import Control.Monad.Catch (MonadCatch)
34import Control.Monad.Catch (MonadCatch)
33import Control.Monad.IO.Class (MonadIO)
35import Control.Monad.IO.Class (MonadIO)
34import qualified Data.Text.Encoding as Text
36import qualified Data.Text.Encoding as Text
37+import GHC.TypeLits (Symbol)
35import Network.Google.Auth.Scope (AllowScopes (..),
38import Network.Google.Auth.Scope (AllowScopes (..),
36 queryEncodeScopes)
39 queryEncodeScopes)
37import Network.Google.Internal.Auth
40import Network.Google.Internal.Auth
@@ -52,23 +55,22 @@ import qualified Network.HTTP.Conduit as Client
52-- > {-# LANGUAGE ScopedTypeVariables #-}
55-- > {-# LANGUAGE ScopedTypeVariables #-}
53--
56--
54-- > import Data.Proxy (Proxy (..))
57-- > import Data.Proxy (Proxy (..))
58+-- > import Data.Text as T
59+-- > import Data.Text.IO as T
55-- > import System.Exit (exitFailure)
60-- > import System.Exit (exitFailure)
56-- > import System.Info (os)
61-- > import System.Info (os)
57-- > import System.Process (rawSystem)
62-- > import System.Process (rawSystem)
58--
63--
59−-- > import qualified Data.ByteString as BS
60−-- > import qualified Data.ByteString.Lazy.Char8 as LBS8
61−-- >
62−-- > redirectPrompt :: forall s. OAuthClient -> proxy s -> IO (OAuthCode s)
64+-- > redirectPrompt :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> IO (OAuthCode s)
63-- > redirectPrompt c p = do
65-- > redirectPrompt c p = do
64−-- > let url = LBS8.unpack (formURL c (Proxy :: Proxy s))
66+-- > let url = formURL c p
65−-- > putStrLn $ "Opening URL " ++ url
67+-- > T.putStrLn $ "Opening URL " `T.append` url
66−-- > case os of
68+-- > _ <- case os of
67−-- > "darwin" -> rawSystem "open" [url]
69+-- > "darwin" -> rawSystem "open" [unpack url]
68−-- > "linux" -> rawSystem "xdg-open" [url]
70+-- > "linux" -> rawSystem "xdg-open" [unpack url]
69−-- > _ -> putStrLn "Unsupported OS" >> exitFailure
71+-- > _ -> T.putStrLn "Unsupported OS" >> exitFailure
70−-- > putStrLn "Please input the authorisation code: "
72+-- > T.putStrLn "Please input the authorisation code: "
71−-- > OAuthCode . LBS.fromStrict <$> BS.getLine
73+-- > OAuthCode <$> T.getLine
72--
74--
73-- This ensures the scopes passed to 'formURL' and the type of 'OAuthCode' 's'
75-- This ensures the scopes passed to 'formURL' and the type of 'OAuthCode' 's'
74-- are correct.
76-- are correct.
@@ -83,7 +85,7 @@ redirectURI = "urn:ietf:wg:oauth:2.0:oob"
83-- construct a URL that can be used to obtain the 'OAuthCode'.
85-- construct a URL that can be used to obtain the 'OAuthCode'.
84--
86--
85-- /See:/ <https://developers.google.com/accounts/docs/OAuth2InstalledApp#formingtheurl Forming the URL>.
87-- /See:/ <https://developers.google.com/accounts/docs/OAuth2InstalledApp#formingtheurl Forming the URL>.
86−formURL :: AllowScopes s => OAuthClient -> proxy s -> Text
88+formURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> Text
87formURL c = formURLWith c . allowScopes
89formURL c = formURLWith c . allowScopes
88
90
89-- | Form a URL using 'OAuthScope' values.
91-- | Form a URL using 'OAuthScope' values.
gogol/src/Network/Google/Auth/ServiceAccount.hs+1−1
@@ -76,7 +76,7 @@ authorizedUserToken u r = refreshRequest $
76 <> "&refresh_token=" <> toQueryParam (fromMaybe (_userRefresh u) r)
76 <> "&refresh_token=" <> toQueryParam (fromMaybe (_userRefresh u) r)
77 }
77 }
78
78
79−-- | Obtain an 'OAuthToken' from @https://accounts.google.com/o/oauth2/token@
79+-- | Obtain an 'OAuthToken' from @https://accounts.google.com/o/oauth2/v2/auth@
80-- by signing and sending a JSON Web Token (JWT) using the supplied 'ServiceAccount'.
80-- by signing and sending a JSON Web Token (JWT) using the supplied 'ServiceAccount'.
81serviceAccountToken :: (MonadIO m, MonadCatch m, AllowScopes s)
81serviceAccountToken :: (MonadIO m, MonadCatch m, AllowScopes s)
82 => ServiceAccount
82 => ServiceAccount
gogol/src/Network/Google/Internal/Auth.hs+3−3
@@ -245,9 +245,9 @@ instance FromJSON RefreshError where
245 <$> o .: "error"
245 <$> o .: "error"
246 <*> o .:? "error_description"
246 <*> o .:? "error_description"
247
247
248−-- | @https://accounts.google.com/o/oauth2/token@.
248+-- | @https://accounts.google.com/o/oauth2/v2/auth@.
249accountsURL :: Text
249accountsURL :: Text
250−accountsURL = "https://accounts.google.com/o/oauth2/token"
250+accountsURL = "https://accounts.google.com/o/oauth2/v2/auth"
251
251
252accountsRequest :: Client.Request
252accountsRequest :: Client.Request
253accountsRequest = def
253accountsRequest = def
@@ -256,7 +256,7 @@ accountsRequest = def
256 , Client.secure = True
256 , Client.secure = True
257 , Client.checkStatus = \_ _ _ -> Nothing
257 , Client.checkStatus = \_ _ _ -> Nothing
258 , Client.method = "POST"
258 , Client.method = "POST"
259− , Client.path = "/o/oauth2/token"
259+ , Client.path = "/o/oauth2/v2/auth"
260 , Client.requestHeaders =
260 , Client.requestHeaders =
261 [ (hContentType, "application/x-www-form-urlencoded")
261 [ (hContentType, "application/x-www-form-urlencoded")
262 ]
262 ]