@@ -1,4 +1,6 @@
1+{-# LANGUAGE KindSignatures #-}
12{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE DataKinds #-}
24
35-- |
46-- Module : Network.Google.Auth.InstalledApplication
@@ -32,6 +34,7 @@ module Network.Google.Auth.InstalledApplication
3234import Control.Monad.Catch (MonadCatch)
3335import Control.Monad.IO.Class (MonadIO)
3436import qualified Data.Text.Encoding as Text
37+import GHC.TypeLits (Symbol)
3538import Network.Google.Auth.Scope (AllowScopes (..),
3639 queryEncodeScopes)
3740import Network.Google.Internal.Auth
@@ -52,23 +55,22 @@ import qualified Network.HTTP.Conduit as Client
5255-- > {-# LANGUAGE ScopedTypeVariables #-}
5356--
5457-- > import Data.Proxy (Proxy (..))
58+-- > import Data.Text as T
59+-- > import Data.Text.IO as T
5560-- > import System.Exit (exitFailure)
5661-- > import System.Info (os)
5762-- > import System.Process (rawSystem)
5863--
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)
6365-- > redirectPrompt c p = do
64−-- > let url = LBS8.unpack (formURL c (Proxy :: Proxy s))
65−-- > putStrLn $ "Opening URL " ++ url
66−-- > case os of
67−-- > "darwin" -> rawSystem "open" [url]
68−-- > "linux" -> rawSystem "xdg-open" [url]
69−-- > _ -> putStrLn "Unsupported OS" >> exitFailure
70−-- > putStrLn "Please input the authorisation code: "
71−-- > OAuthCode . LBS.fromStrict <$> BS.getLine
66+-- > let url = formURL c p
67+-- > T.putStrLn $ "Opening URL " `T.append` url
68+-- > _ <- case os of
69+-- > "darwin" -> rawSystem "open" [unpack url]
70+-- > "linux" -> rawSystem "xdg-open" [unpack url]
71+-- > _ -> T.putStrLn "Unsupported OS" >> exitFailure
72+-- > T.putStrLn "Please input the authorisation code: "
73+-- > OAuthCode <$> T.getLine
7274--
7375-- This ensures the scopes passed to 'formURL' and the type of 'OAuthCode' 's'
7476-- are correct.
@@ -83,7 +85,7 @@ redirectURI = "urn:ietf:wg:oauth:2.0:oob"
8385-- construct a URL that can be used to obtain the 'OAuthCode'.
8486--
8587-- /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
8789formURL c = formURLWith c . allowScopes
8890
8991-- | Form a URL using 'OAuthScope' values.