gogol-0.4.0: Comprehensive Google Services SDK.

Copyright(c) 2015-2016 Brendan Hay
LicenseMozilla Public License, v. 2.0.
MaintainerBrendan Hay <brendan.g.hay@gmail.com>
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Network.Google.Auth.InstalledApplication

Contents

Description

Credentials for applications that are installed on devices such as computers, cell phones, or a tablet. Installed apps are distributed to individual machines, and it is assumed that these apps securely store secrets.

These apps might access a Google service while the user is present at the application, or when the application is running in the background.

See: Installed Application Documentation.

Synopsis

Documentation

installedApplication :: OAuthClient -> OAuthCode s -> Credentials s Source #

Create new Installed Application credentials.

Since it is intended that the user opens the URL generated by formURL in a browser and the resulting OAuthCode is then received out-of-band, you must ensure that the scopes passed to formURL and the type of OAuthCode correctly match, otherwise an authorization error will occur.

For example, doing this via getLine and copy-paste:

{-# 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)
redirectPrompt :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> IO (OAuthCode s)
redirectPrompt c p = do
  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.

Forming the URL

redirectURI :: Text Source #

The redirection URI used in formURL: urn:ietf:wg:oauth:2.0:oob.

formURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> Text Source #

Given an OAuthClient and a list of scopes to authorize, construct a URL that can be used to obtain the OAuthCode.

See: Forming the URL.

formAccessTypeURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> AccessType -> proxy s -> Text Source #

formURL for AccessType

See: formUrl.

formURLWith :: OAuthClient -> [OAuthScope] -> Text Source #

Form a URL using OAuthScope values.

See: formURL.

Internal Exchange and Refresh

exchangeCode :: (MonadIO m, MonadCatch m) => OAuthClient -> OAuthCode s -> Logger -> Manager -> m (OAuthToken s) Source #

Exchange OAuthClient details and the received OAuthCode for a new OAuthToken.

See: Exchanging the code.

refreshToken :: (MonadIO m, MonadCatch m) => OAuthClient -> OAuthToken s -> Logger -> Manager -> m (OAuthToken s) Source #

Perform a refresh to obtain a valid OAuthToken with a new expiry time.

See: Refreshing tokens.