Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/OJ/erl_openid
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtj committed Oct 24, 2010
2 parents 8dd16e2 + d54353e commit 28e24d1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
45 changes: 19 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
SRC_DIR = src
EBIN_DIR = ebin
INCLUDE_DIR = include
ERL ?= erl
APP := openid

SOURCES = $(wildcard $(SRC_DIR)/*.erl)
INCLUDES = $(wildcard $(INCLUDE_DIR)/*.hrl)
TARGETS = $(patsubst $(SRC_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(SOURCES))
.PHONY: deps
.PHONY: test
.PHONY: mod

ERL_EBINS = -pa $(EBIN_DIR)
all: deps
@./rebar compile

ERLC = erlc
ERLC_OPTS = -o $(EBIN_DIR) -Wall -v +debug_info
deps:
@./rebar get-deps

ERL_CMD=erl \
+W w \
$(ERL_EBINS)
clean:
@./rebar clean

all: $(TARGETS)
mod:
@./rebar create-mod app=$(APP) modid=$(MOD)

run_prereqs: all
test:
@./rebar eunit app=$(APP)

test: run_prereqs
$(ERL_CMD) -noshell -pa ../mochiweb/ebin -s openid_srv test -s init stop
distclean: clean
@./rebar delete-deps

clean: cleanlog
rm -f $(TARGETS)
rm -f $(EBIN_DIR)/*.beam

cleanlog:
rm -f auth.log report.log sasl_err.log
rm -f *.access

$(EBIN_DIR)/%.beam: $(SRC_DIR)/%.erl $(INCLUDES)
$(ERLC) $(ERLC_OPTS) $<
docs:
@erl -noshell -run edoc_run application '$(APP)' '"."' '[]'
14 changes: 14 additions & 0 deletions ebin/openid.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{application,
openid,
[{description, "OpenID 2.0 implementation"},
{vsn, "0.0.1"},
{modules,
[
openid,
openid_utils,
openid_srv,
yadis
]},
{registered,[]},
{applications,[kernel, stdlib]},
{env,[]}]}.
Binary file added rebar
Binary file not shown.
10 changes: 3 additions & 7 deletions src/openid.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

-include("openid.hrl").

-define(GV(E, P), proplists:get_value(E, P)).
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).



%% ------------------------------------------------------------
Expand All @@ -25,7 +21,7 @@ discover(Identifier) ->
Req = case yadis:retrieve(Identifier) of
{none, Body} -> html_discovery(Body);
#xrds{}=XRDS -> extract_authreq(XRDS);
{error, Error} ->
{error, _Error} ->
%?DBG({error, Error}),
none
end,
Expand Down Expand Up @@ -143,7 +139,7 @@ associate(OpURL) ->

%?DBG({pub_priv, Public, Private, size(Public), size(Private)}),

RollPub = roll(Public),
_RollPub = roll(Public),
%?DBG({rolled, RollPub, size(RollPub)}),

Params = [{"openid.ns", "http://specs.openid.net/auth/2.0"},
Expand All @@ -158,7 +154,7 @@ associate(OpURL) ->

Request = {OpURL, [], ?CONTENT_TYPE, ReqBody},

{ok, {_,_,Body}} = http:request(post, Request, [], []),
{ok, {_,_,Body}} = httpc:request(post, Request, [], []),

Response = parse_keyvalue(Body),

Expand Down
4 changes: 4 additions & 0 deletions src/openid.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
%%% Created : 18 Sep 2009 by Brendon Hogger <[email protected]>
%%%-------------------------------------------------------------------

-define(GV(E, P), proplists:get_value(E, P)).
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).

-record(xrdService, {
types,
uris,
Expand Down
8 changes: 2 additions & 6 deletions src/openid_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ start_link(Name) ->
%% gen_server callbacks
%%====================================================================

-define(GV(E, P), proplists:get_value(E, P)).
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).

init(_Args) ->
AuthReqs = ets:new(openid_authreqs, [set, private]),
Assocs = ets:new(openid_assocs, [set, private]),
Expand Down Expand Up @@ -248,9 +244,9 @@ verify_signature(ClaimedID, Assoc, Fields) ->
Invalidate = ?GVD("openid.invalidate_handle", Fields, false),
verify_signature(ClaimedID, Invalidate, Assoc, Fields).

verify_signature(_, _, none, Fields) ->
verify_signature(_, _, none, _Fields) ->
{error, "Direct verification not implemented yet"};
verify_signature(ClaimedID, false, #assoc{}=Assoc, Fields) ->
verify_signature(_ClaimedID, false, #assoc{}=Assoc, Fields) ->
KV = lists:flatten([[Key,$:,?GV("openid." ++ Key, Fields),$\n]
|| Key <- string:tokens(?GV("openid.signed", Fields), ",")]),
MAC = Assoc#assoc.mac,
Expand Down
15 changes: 7 additions & 8 deletions src/openid_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ skip_tag([$>|Rest], State) -> find_tags(Rest, State);
skip_tag("", State) -> find_tags("", State);
skip_tag([_|Rest], State) -> skip_tag(Rest, State).

check_attrs(PropList, Tail, {Buffer,Tag,none,none}) ->
find_tags(Tail, {[PropList|Buffer],Tag,none,none});
check_attrs(PropList, Tail, {_,_,Key,Val}=State) ->
case ?GVD(Key, PropList, none) of
none -> find_tags(Tail, State);
IVal -> check_val(string:to_lower(IVal), Val, PropList, Tail, State)
end.

get_tag_content(Rest, State) ->
{Content, Tail} = get_raw_content(Rest, []),
Expand All @@ -52,14 +59,6 @@ get_tag_content(Rest, State) ->
get_raw_content(">" ++ Tail, Content) -> {lists:reverse(Content), Tail};
get_raw_content([Char|Rest], Bits) -> get_raw_content(Rest, [Char|Bits]).

check_attrs(PropList, Tail, {Buffer,Tag,none,none}) ->
find_tags(Tail, {[PropList|Buffer],Tag,none,none});
check_attrs(PropList, Tail, {_,_,Key,Val}=State) ->
case ?GVD(Key, PropList, none) of
none -> find_tags(Tail, State);
IVal -> check_val(string:to_lower(IVal), Val, PropList, Tail, State)
end.

check_val(V, V, PropList, Tail, {Buffer,Tag,Key,Val})->
find_tags(Tail, {[PropList|Buffer],Tag,Key,Val});
check_val(_, _, _, Tail, State) ->
Expand Down
6 changes: 2 additions & 4 deletions src/yadis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
-include("openid.hrl").
-include_lib("xmerl/include/xmerl.hrl").

-define(GVD(E, P, D), proplists:get_value(E, P, D)).

-define(HTTP_HEADERS, [{"Accept", "application/xrds+xml"},
{"Connection", "close"},
{"User-Agent", "Erlang/openid"}]).
Expand Down Expand Up @@ -48,7 +46,7 @@ retrieve(Identifier) ->
false -> Normalized
end,

case http:request(get, {URL, ?HTTP_HEADERS}, ?HTTP_OPTIONS, ?REQ_OPTIONS) of
case httpc:request(get, {URL, ?HTTP_HEADERS}, ?HTTP_OPTIONS, ?REQ_OPTIONS) of
{ok, {_Status, Headers, Body}} ->
DescriptorURL = get_descriptor_url(Headers, Body),
XRDS = handle_response(DescriptorURL, Headers, Body),
Expand Down Expand Up @@ -103,7 +101,7 @@ try_descriptor_url(URL) -> retrieve_step_two(URL).


retrieve_step_two(YadisURL) ->
case http:request(get, {YadisURL, ?HTTP_HEADERS}, ?HTTP_OPTIONS, ?REQ_OPTIONS) of
case httpc:request(get, {YadisURL, ?HTTP_HEADERS}, ?HTTP_OPTIONS, ?REQ_OPTIONS) of
{ok, {_Status, Headers, Body}} ->
get_xrds(?GVD("content-type", Headers, none), Body);
Other ->
Expand Down

0 comments on commit 28e24d1

Please sign in to comment.