@@ -1,4 +1,6 @@
1+{-# LANGUAGE KindSignatures #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE DataKinds #-}
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 #-}
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)
59−-- > import qualified Data.ByteString as BS
60−-- > import qualified Data.ByteString.Lazy.Char8 as LBS8
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
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'.
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
89-- | Form a URL using 'OAuthScope' values.
91-- | Form a URL using 'OAuthScope' values.