The google-oauth2 package

[ Tags: library, mit, unclassified ] [ Propose Tags ]

Interacting with the Google OAuth2 authorization API

  1. Prompt the user for a verification code

  2. POST that code to the Google API for a set of tokens (access and refresh)

  3. Use the access token until it expires

  4. Use the refresh token to get a new access token

  5. Repeat from 3

Example usage:

import Data.Monoid
import Network.Google.OAuth2
import Network.HTTP.Conduit
import Network.HTTP.Types (hAuthorization)

import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8

main :: IO ()
main = do
    let client = OAuth2Client clientId clientSecret
        scopes = ["https://www.googleapis.com/auth/drive"]

    token <- getAccessToken client scopes Nothing

    request <- parseUrl "https://www.googleapis.com/drive/v2/files"
    response <- withManager $ httpLbs $ authorize token request

    L8.putStrLn $ responseBody response

 where
   authorize token request = request
       -- Note: haddock chokes on curly braces for some reason, so I'm using
       -- parens here instead.
       ( requestHeaders = [(hAuthorization, B8.pack $ "Bearer " <> token)] )

   -- Setup in Google Developers Console
   clientId = "..."
   clientSecret = "..."

Properties

Versions 0.1.0, 0.2.0, 0.2.1, 0.2.2
Dependencies aeson (>=0.8 && <0.12), base (==4.*), bytestring, HTTP (>=4000.2 && <4000.4), http-conduit [details]
License MIT
Author Pat Brisbin <pbrisbin@gmail.com>
Maintainer Pat Brisbin <pbrisbin@gmail.com>
Source repository head: git clone https://github.com/pbrisbin/google-oauth2
Uploaded Sat Nov 19 21:24:35 UTC 2016 by PatrickBrisbin
Distributions NixOS:0.2.2
Downloads 629 total (73 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-11-19 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees