Google OAuth2 token negotiation
Switch branches/tags
Clone or download
Latest commit e7ef274 Apr 24, 2018

README.md

Google OAuth2

Interactive Google OAuth2 token negotiation

Usage

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Main (main) where

import Data.Aeson
import Data.Semigroup ((<>))
import Network.Google.OAuth2
import Network.HTTP.Conduit.Simple
import Network.OAuth.OAuth2
improt Data.Text.Excoding (encodeUtf8)

main :: IO ()
main = do
    OAuth2Token{..} <-
      getAccessToken
        "CLIENT_ID"
        "CLIENT_SECRET"
        ["https://www.googleapis.com/auth/drive"]
        (Just "path/to/credentials.cache")

    request <- parseRequest "https://www.googleapis.com/drive/v2/files"
    response <- httpJSON $ authorize (atoken accessToken) request

    print (getResponseBody response :: Value)
 where
   authorize token = setRequestHeaders
       [ ("Authorization", encodeUtf8 $ "Bearer " <> token)
       ]

Prior Art

This module was inspired by handa-gdata which appears to be abandoned.


CHANGELOG | LICENSE