| Copyright | (c) 2015-2016 Brendan Hay |
|---|---|
| License | Mozilla Public License, v. 2.0. |
| Maintainer | Brendan Hay <brendan.g.hay@gmail.com> |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
Network.Google.Auth.InstalledApplication
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.
Synopsis
- installedApplication :: OAuthClient -> OAuthCode s -> Credentials s
- data AccessType
- redirectURI :: Text
- formURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> Text
- formAccessTypeURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> AccessType -> proxy s -> Text
- formURLWith :: OAuthClient -> [OAuthScope] -> Text
- formAccessTypeURLWith :: OAuthClient -> AccessType -> [OAuthScope] -> Text
- exchangeCode :: (MonadIO m, MonadCatch m) => OAuthClient -> OAuthCode s -> Logger -> Manager -> m (OAuthToken s)
- refreshToken :: (MonadIO m, MonadCatch m) => OAuthClient -> OAuthToken s -> Logger -> Manager -> m (OAuthToken s)
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.getLineThis ensures the scopes passed to formURL and the type of OAuthCode s
are correct.
Forming the URL
data AccessType Source #
Instances
| Eq AccessType Source # | |
Defined in Network.Google.Auth.InstalledApplication | |
| Show AccessType Source # | |
Defined in Network.Google.Auth.InstalledApplication Methods showsPrec :: Int -> AccessType -> ShowS # show :: AccessType -> String # showList :: [AccessType] -> ShowS # | |
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.
formAccessTypeURLWith :: OAuthClient -> AccessType -> [OAuthScope] -> Text Source #
See: formURLWith.
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.