Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for installed application auth example #39

Merged
merged 3 commits into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions gogol/src/Network/Google/Auth/InstalledApplication.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}

-- |
-- Module : Network.Google.Auth.InstalledApplication
Expand Down Expand Up @@ -32,6 +34,7 @@ module Network.Google.Auth.InstalledApplication
import Control.Monad.Catch (MonadCatch)
import Control.Monad.IO.Class (MonadIO)
import qualified Data.Text.Encoding as Text
import GHC.TypeLits (Symbol)
import Network.Google.Auth.Scope (AllowScopes (..),
queryEncodeScopes)
import Network.Google.Internal.Auth
Expand All @@ -52,23 +55,22 @@ import qualified Network.HTTP.Conduit as Client
-- > {-# LANGUAGE ScopedTypeVariables #-}
--
-- > import Data.Proxy (Proxy (..))
-- > import Data.Text as T
-- > import Data.Text.IO as T
-- > import System.Exit (exitFailure)
-- > import System.Info (os)
-- > import System.Process (rawSystem)
--
-- > import qualified Data.ByteString as BS
-- > import qualified Data.ByteString.Lazy.Char8 as LBS8
-- >
-- > redirectPrompt :: forall s. OAuthClient -> proxy s -> IO (OAuthCode s)
-- > redirectPrompt :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> IO (OAuthCode s)
-- > redirectPrompt c p = do
-- > let url = LBS8.unpack (formURL c (Proxy :: Proxy s))
-- > putStrLn $ "Opening URL " ++ url
-- > case os of
-- > "darwin" -> rawSystem "open" [url]
-- > "linux" -> rawSystem "xdg-open" [url]
-- > _ -> putStrLn "Unsupported OS" >> exitFailure
-- > putStrLn "Please input the authorisation code: "
-- > OAuthCode . LBS.fromStrict <$> BS.getLine
-- > let url = formURL c p
-- > T.putStrLn $ "Opening URL " `T.append` url
-- > _ <- case os of
-- > "darwin" -> rawSystem "open" [unpack url]
-- > "linux" -> rawSystem "xdg-open" [unpack url]
-- > _ -> T.putStrLn "Unsupported OS" >> exitFailure
-- > T.putStrLn "Please input the authorisation code: "
-- > OAuthCode <$> T.getLine
--
-- This ensures the scopes passed to 'formURL' and the type of 'OAuthCode' 's'
-- are correct.
Expand All @@ -83,7 +85,7 @@ redirectURI = "urn:ietf:wg:oauth:2.0:oob"
-- construct a URL that can be used to obtain the 'OAuthCode'.
--
-- /See:/ <https://developers.google.com/accounts/docs/OAuth2InstalledApp#formingtheurl Forming the URL>.
formURL :: AllowScopes s => OAuthClient -> proxy s -> Text
formURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> Text
formURL c = formURLWith c . allowScopes

-- | Form a URL using 'OAuthScope' values.
Expand Down
2 changes: 1 addition & 1 deletion gogol/src/Network/Google/Auth/ServiceAccount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ authorizedUserToken u r = refreshRequest $
<> "&refresh_token=" <> toQueryParam (fromMaybe (_userRefresh u) r)
}

-- | Obtain an 'OAuthToken' from @https://accounts.google.com/o/oauth2/token@
-- | Obtain an 'OAuthToken' from @https://accounts.google.com/o/oauth2/v2/auth@
-- by signing and sending a JSON Web Token (JWT) using the supplied 'ServiceAccount'.
serviceAccountToken :: (MonadIO m, MonadCatch m, AllowScopes s)
=> ServiceAccount
Expand Down
6 changes: 3 additions & 3 deletions gogol/src/Network/Google/Internal/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ instance FromJSON RefreshError where
<$> o .: "error"
<*> o .:? "error_description"

-- | @https://accounts.google.com/o/oauth2/token@.
-- | @https://accounts.google.com/o/oauth2/v2/auth@.
accountsURL :: Text
accountsURL = "https://accounts.google.com/o/oauth2/token"
accountsURL = "https://accounts.google.com/o/oauth2/v2/auth"

accountsRequest :: Client.Request
accountsRequest = def
Expand All @@ -256,7 +256,7 @@ accountsRequest = def
, Client.secure = True
, Client.checkStatus = \_ _ _ -> Nothing
, Client.method = "POST"
, Client.path = "/o/oauth2/token"
, Client.path = "/o/oauth2/v2/auth"
, Client.requestHeaders =
[ (hContentType, "application/x-www-form-urlencoded")
]
Expand Down