Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/_build
**/public_key.pem
**/*.byte
**/*.native
setup.data
setup.log
6 changes: 0 additions & 6 deletions META

This file was deleted.

71 changes: 38 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
OCAMLDIR=`ocamlfind printconf stdlib`
FILES=\
ooauth.cma ooauth.cmxa ooauth.a \
oauth_client.mli oauth_client.cmi \
oauth_server.mli oauth_server.cmi \
oauth_base32.mli oauth_base32.cmi \
oauth_util.cmi \
oauth_ocurl_http_client.cmi \
oauth_netclient_http_client.cmi \
oauth_netcgi_http.cmi

BFILES=$(addprefix _build/,$(FILES))

all: pem2cryptokit
ocamlbuild ooauth.cma ooauth.cmxa

pem2cryptokit: pem2cryptokit.c
gcc -g -I$(OCAMLDIR) pem2cryptokit.c -L$(OCAMLDIR) -lssl -lcrypto -lcamlrun -lm -o pem2cryptokit

install: all
ocamlfind install ooauth META $(BFILES)
cp pem2cryptokit $(OCAMLDIR)/../../bin

uninstall:
ocamlfind remove ooauth

clean:
ocamlbuild -clean
rm -f pem2cryptokit
$(MAKE) -C examples clean

dist: clean
cd ..; tar cvfz ooauth.tar.gz --exclude .svn ooauth
# OASIS_START
# DO NOT EDIT (digest: bc1e05bfc8b39b664f29dae8dbd3ebbb)

SETUP = ocaml setup.ml

build: setup.data
$(SETUP) -build $(BUILDFLAGS)

doc: setup.data build
$(SETUP) -doc $(DOCFLAGS)

test: setup.data build
$(SETUP) -test $(TESTFLAGS)

all:
$(SETUP) -all $(ALLFLAGS)

install: setup.data
$(SETUP) -install $(INSTALLFLAGS)

uninstall: setup.data
$(SETUP) -uninstall $(UNINSTALLFLAGS)

reinstall: setup.data
$(SETUP) -reinstall $(REINSTALLFLAGS)

clean:
$(SETUP) -clean $(CLEANFLAGS)

distclean:
$(SETUP) -distclean $(DISTCLEANFLAGS)

setup.data:
$(SETUP) -configure $(CONFIGUREFLAGS)

.PHONY: build doc test all install uninstall reinstall clean distclean configure

# OASIS_STOP
16 changes: 0 additions & 16 deletions README

This file was deleted.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is OOAuth, OAuth for OCaml, version 0.1.

## Requirements:

- cryptokit
- ocamlnet
- ocaml-crypto-keys (https://github.com/crotsos/ocaml-crypto-keys)
- ocurl (optional)

## To configure:

If you don't have Ocurl, remove references to it from ooauth.mllib, META, and FILES in Makefile.

## To install:

* make
* make install

After installing, try the example in examples/term.ie/.
59 changes: 59 additions & 0 deletions _oasis
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
OASISFormat: 0.3
Name: ooauth
Version: 0.1
Synopsis: OAuth for OCaml
Authors: Jake Donham, Vincent Bernardoff
License: ISC
Plugins: META (0.3), DevFiles (0.3)
BuildTools: ocamlbuild

Flag cohttp
Description: build the Cohttp library
Default: true

Flag ocurl
Description: build the OCurl library
Default: false

Flag ocamlnet
Description: build the Ocamlnet library
Default: false

Library oauth
Path: lib
Findlibname: oauth
Modules: Oauth_util, Oauth_base32, Oauth_common, Oauth_client, Oauth_server
BuildDepends: cryptokit, uri, re.pcre

Library oauth_cohttp
Build$: flag(cohttp)
Install$: flag(cohttp)
Path: cohttp
Findlibname: cohttp
Findlibparent: oauth
BuildDepends: oauth, cohttp.lwt
Modules: Oauth_cohttp_http, Oauth_cohttp_http_client

Executable client_termie
Path: examples/term.ie
BuildDepends: oauth.cohttp
MainIs: client.ml
CompiledObject: best
Build: true
Install: false

Executable client_localhost
Path: examples/localhost
BuildDepends: oauth.cohttp
MainIs: client.ml
CompiledObject: best
Build: true
Install: false

Executable server_localhost
Path: examples/localhost
BuildDepends: oauth.cohttp
MainIs: server_cohttp.ml
CompiledObject: best
Build: true
Install: false
65 changes: 61 additions & 4 deletions _tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
<*.ml*> : debug,pkg_cryptokit,pkg_netstring
<oauth_ocurl_http_client.ml> : pkg_curl
<oauth_netclient_http_client.ml> : pkg_netclient
<oauth_netcgi_http.ml> : pkg_netcgi2
# OASIS_START
# DO NOT EDIT (digest: c7f1bd9cf1aa400dc719cdeeb67ff922)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
<**/.svn>: -traverse
<**/.svn>: not_hygienic
".bzr": -traverse
".bzr": not_hygienic
".hg": -traverse
".hg": not_hygienic
".git": -traverse
".git": not_hygienic
"_darcs": -traverse
"_darcs": not_hygienic
# Library oauth
"lib/oauth.cmxs": use_oauth
<lib/*.ml{,i}>: pkg_cryptokit
<lib/*.ml{,i}>: pkg_uri
<lib/*.ml{,i}>: pkg_re.pcre
# Library oauth_cohttp
"cohttp/oauth_cohttp.cmxs": use_oauth_cohttp
<cohttp/*.ml{,i}>: use_oauth
<cohttp/*.ml{,i}>: pkg_cohttp.lwt
<cohttp/*.ml{,i}>: pkg_cryptokit
<cohttp/*.ml{,i}>: pkg_uri
<cohttp/*.ml{,i}>: pkg_re.pcre
# Executable client_termie
<examples/term.ie/client.{native,byte}>: use_oauth_cohttp
<examples/term.ie/client.{native,byte}>: use_oauth
<examples/term.ie/client.{native,byte}>: pkg_cohttp.lwt
<examples/term.ie/client.{native,byte}>: pkg_cryptokit
<examples/term.ie/client.{native,byte}>: pkg_uri
<examples/term.ie/client.{native,byte}>: pkg_re.pcre
<examples/term.ie/*.ml{,i}>: use_oauth_cohttp
<examples/term.ie/*.ml{,i}>: use_oauth
<examples/term.ie/*.ml{,i}>: pkg_cohttp.lwt
<examples/term.ie/*.ml{,i}>: pkg_cryptokit
<examples/term.ie/*.ml{,i}>: pkg_uri
<examples/term.ie/*.ml{,i}>: pkg_re.pcre
# Executable client_localhost
<examples/localhost/client.{native,byte}>: use_oauth_cohttp
<examples/localhost/client.{native,byte}>: use_oauth
<examples/localhost/client.{native,byte}>: pkg_cohttp.lwt
<examples/localhost/client.{native,byte}>: pkg_cryptokit
<examples/localhost/client.{native,byte}>: pkg_uri
<examples/localhost/client.{native,byte}>: pkg_re.pcre
# Executable server_localhost
<examples/localhost/server_cohttp.{native,byte}>: use_oauth_cohttp
<examples/localhost/server_cohttp.{native,byte}>: use_oauth
<examples/localhost/server_cohttp.{native,byte}>: pkg_cohttp.lwt
<examples/localhost/server_cohttp.{native,byte}>: pkg_cryptokit
<examples/localhost/server_cohttp.{native,byte}>: pkg_uri
<examples/localhost/server_cohttp.{native,byte}>: pkg_re.pcre
<examples/localhost/*.ml{,i}>: use_oauth_cohttp
<examples/localhost/*.ml{,i}>: use_oauth
<examples/localhost/*.ml{,i}>: pkg_cohttp.lwt
<examples/localhost/*.ml{,i}>: pkg_cryptokit
<examples/localhost/*.ml{,i}>: pkg_uri
<examples/localhost/*.ml{,i}>: pkg_re.pcre
# OASIS_STOP
5 changes: 5 additions & 0 deletions cohttp/oauth_cohttp.mllib
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: cfc2e2d8157ac69c166bc821d9df1bcb)
Oauth_cohttp_http
Oauth_cohttp_http_client
# OASIS_STOP
42 changes: 42 additions & 0 deletions cohttp/oauth_cohttp_http.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module C = Cohttp
module CU = Cohttp_lwt_unix
module CB = Cohttp_lwt_body

let (>>=) = Lwt.bind

module Monad = Lwt

type status_code = int
type meth = C.Code.meth

type request = CU.Server.Request.t

exception Error of status_code * string

let http_method = CU.Request.meth

let url req = Uri.to_string (CU.Request.uri req)

let header req h =
let hs = CU.Request.headers req in
match C.Header.get hs (String.lowercase h) with
| Some h -> h
| None -> raise Not_found

let argument req ?default arg =
let uri = CU.Request.uri req in
match default, Uri.get_query_param uri arg with
| _, Some v -> v
| Some d, None -> d
| _ -> raise Not_found

let arguments req =
let uri = CU.Request.uri req in
List.map (fun (k,vs) -> (k, List.hd vs)) (Uri.query uri)

type response = (CU.Response.t * Cohttp_lwt_body.t)

let respond req status headers body =
let headers = C.Header.of_list headers in
let status = C.Code.status_of_code status in
CU.Server.respond_string ~headers ~status ~body ()
37 changes: 37 additions & 0 deletions cohttp/oauth_cohttp_http_client.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module C = Cohttp
module CU = Cohttp_lwt_unix
module CB = Cohttp_lwt_body

let (>>=) = Lwt.bind

type status_code = int
type meth = C.Code.meth

module Opt = struct
type 'a t = 'a option
let (>>=) x f = match x with Some v -> f v | None -> None
let (>|=) x f = match x with Some v -> Some (f v) | None -> None
let run x = match x with Some v -> v | None -> raise (Invalid_argument "run")
let default d x = match x with Some v -> v | None -> d
end

module Monad = Lwt

let request ?http_method ~url ?headers ?params ?body () =
let uri = Uri.of_string url in
let uri = match params with
| Some p -> Uri.with_query' uri p
| None -> uri
in
CU.Client.call
?headers:Opt.(headers >|= fun hs -> C.Header.of_list hs)
?body:Opt.(body >>= fun (content_type, body) -> CB.body_of_string body)
Opt.(default `GET http_method)
uri
>>= function
| None -> Lwt.fail (Failure "Connection did not succeed")
| Some (response, body) ->
let status = CU.Response.status response |> C.Code.code_of_status in
let headers = C.Header.to_list (CU.Response.headers response) in
CB.string_of_body body >>= fun body_string ->
Lwt.return (status, headers, body_string)
27 changes: 27 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# OASIS_START
# DO NOT EDIT (digest: 425187ed8bfdbdd207fd76392dd243a7)
set -e

FST=true
for i in "$@"; do
if $FST; then
set --
FST=false
fi

case $i in
--*=*)
ARG=${i%%=*}
VAL=${i##*=}
set -- "$@" "$ARG" "$VAL"
;;
*)
set -- "$@" "$i"
;;
esac
done

ocaml setup.ml -configure "$@"
# OASIS_STOP
Loading