google-oauth2: Google OAuth2 token negotiation

[ 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 = "..."

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.3.0.0
Dependencies aeson (>=0.8 && <0.10), base (>=4 && <5), bytestring, HTTP (>=4000.2 && <4000.4), http-conduit [details]
License MIT
Author Pat Brisbin <pbrisbin@gmail.com>
Maintainer Pat Brisbin <pbrisbin@gmail.com>
Source repo head: git clone https://github.com/pbrisbin/google-oauth2
Uploaded by PatrickBrisbin at 2016-03-29T21:24:50Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3703 total (15 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-03-29 [all 1 reports]