Skip to content

Commit

Permalink
Modernize project
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Apr 24, 2018
1 parent ef84bea commit e7ef274
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 384 deletions.
13 changes: 2 additions & 11 deletions .gitignore
@@ -1,13 +1,4 @@
dist
cabal-dev
*.o
*.hi
*.chi
*.chs.h
.virthualenv
.hsenv
.cabal-sandbox/
cabal.sandbox.config

*.cabal
.env
.stack-work
test/oauth.token
4 changes: 4 additions & 0 deletions .hlint.yaml
@@ -0,0 +1,4 @@
---
- ignore:
name: Redundant do
within: spec
21 changes: 21 additions & 0 deletions .stylish-haskell.yaml
@@ -0,0 +1,21 @@
steps:
- simple_align:
cases: false
top_level_patterns: false
records: false
- imports:
align: none
list_align: after_alias
pad_module_names: false
long_list_align: new_line_multiline
empty_list_align: right_after
list_padding: 4
separate_lists: false
space_surround: false
- language_pragmas:
style: vertical
align: false
remove_redundant: true
- trailing_whitespace: {}
columns: 80
newline: native
10 changes: 10 additions & 0 deletions .weeder.yaml
@@ -0,0 +1,10 @@
---
- package:
- name: google-oauth2
- section:
- name: test:spec
- message:
- name: Weeds exported
- module:
- name: Network.Google.OAuth2Spec
- identifier: main
1 change: 1 addition & 0 deletions CHANGELOG.hs
@@ -0,0 +1 @@
TODO
30 changes: 30 additions & 0 deletions Makefile
@@ -0,0 +1,30 @@
all: setup build test lint

.PHONY: setup
setup:
stack setup
stack build \
--dependencies-only --test --no-run-tests
stack install hlint weeder
gpg --output test/oauth.token --decrypt test/oauth.token.gpg

.PHONY: build
build:
stack build \
--coverage \
--fast --pedantic --test --no-run-tests

.PHONY: test
test:
stack build \
--coverage \
--fast --pedantic --test

.PHONY: lint
lint:
hlint .
weeder .

.PHONY: clean
clean:
stack clean
66 changes: 27 additions & 39 deletions README.md
@@ -1,59 +1,47 @@
# Google OAuth2

Google OAuth2 token negotiation

## Installation

```
% cabal install google-oauth2
```
Interactive Google OAuth2 token negotiation

## Usage

```haskell
import Data.Monoid
import Network.Google.OAuth2
import Network.HTTP.Conduit
import Network.HTTP.Types (hAuthorization)
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8
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
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
OAuth2Token{..} <-
getAccessToken
"CLIENT_ID"
"CLIENT_SECRET"
["https://www.googleapis.com/auth/drive"]
(Just "path/to/credentials.cache")

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

print (getResponseBody response :: Value)
where
authorize token request = request
{ requestHeaders = [(hAuthorization, B8.pack $ "Bearer " <> token)] }

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

## Developing and Tests

authorize token = setRequestHeaders
[ ("Authorization", encodeUtf8 $ "Bearer " <> token)
]
```
% cp .env{.example,} # and edit it accordingly
% cabal install --dependencies-only --enable-tests -j
% cabal test
```

Note: The tests require some degree of user interaction. One test will always
need it (that's the aspect it's testing) and is therefore pending by default.
The other test will need interaction the first time its run only.

## Prior Art

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

[handa-gdata]: http://hackage.haskell.org/package/handa-gdata

---

[CHANGELOG](./CHANGELOG.md) | [LICENSE](./LICENSE)
40 changes: 40 additions & 0 deletions brittany.yaml
@@ -0,0 +1,40 @@
---
conf_debug:
dconf_roundtrip_exactprint_only: false
dconf_dump_bridoc_simpl_par: false
dconf_dump_ast_unknown: false
dconf_dump_bridoc_simpl_floating: false
dconf_dump_config: false
dconf_dump_bridoc_raw: false
dconf_dump_bridoc_final: false
dconf_dump_bridoc_simpl_alt: false
dconf_dump_bridoc_simpl_indent: false
dconf_dump_annotations: false
dconf_dump_bridoc_simpl_columns: false
dconf_dump_ast_full: false
conf_forward:
options_ghc: []
conf_errorHandling:
econf_ExactPrintFallback: ExactPrintFallbackModeInline
econf_Werror: false
econf_omit_output_valid_check: false
econf_produceOutputOnErrors: false
conf_preprocessor:
ppconf_CPPMode: CPPModeAbort
ppconf_hackAroundIncludes: false
conf_version: 1
conf_layout:
lconfig_altChooser:
tag: AltChooserBoundedSearch
contents: 3
lconfig_importColumn: 60
lconfig_alignmentLimit: 1
lconfig_indentListSpecial: true
lconfig_indentAmount: 4
lconfig_alignmentBreakOnMultiline: true
lconfig_cols: 80
lconfig_indentPolicy: IndentPolicyLeft
lconfig_indentWhereSpecial: true
lconfig_columnAlignMode:
tag: ColumnAlignModeDisabled
contents: 0.7
Binary file added dist/cabal-config-flags
Binary file not shown.
82 changes: 0 additions & 82 deletions google-oauth2.cabal

This file was deleted.

37 changes: 37 additions & 0 deletions package.yaml
@@ -0,0 +1,37 @@
---
name: google-oauth2
version: 0.3.0.0
synopsis: Google OAuth2 token negotiation
description: See https://github.com/pbrisbin/google-oauth2#readme
author: Pat Brisbin <pbrisbin@gmail.com>
maintainer: Pat Brisbin <pbrisbin@gmail.com>
license: MIT
github: pbrisbin/google-oauth2

dependencies:
- base >=4 && <5
- bytestring
- hoauth2
- text

ghc-options: -Wall

library:
source-dirs: src
ghc-options: -Wall
dependencies:
- http-client-tls
- safe-exceptions
- transformers
- uri-bytestring

tests:
spec:
main: Spec.hs
source-dirs: test
ghc-options: -Wall
dependencies:
- google-oauth2
- hspec
- http-conduit
- load-env

0 comments on commit e7ef274

Please sign in to comment.