Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
294 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- ignore: | ||
name: Redundant do | ||
within: spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- package: | ||
- name: google-oauth2 | ||
- section: | ||
- name: test:spec | ||
- message: | ||
- name: Weeds exported | ||
- module: | ||
- name: Network.Google.OAuth2Spec | ||
- identifier: main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.