Permalink
Browse files

Move .hrl to include and prefix records.

Makes it a bit easier to reuse this as lib.
  • Loading branch information...
andrewtj committed Oct 29, 2010
1 parent 28e24d1 commit faa0e47e107da67d47ce0644e46b6b004f37877a
Showing with 47 additions and 47 deletions.
  1. +4 −4 {src → include}/openid.hrl
  2. +26 −26 src/openid.erl
  3. +11 −11 src/openid_srv.erl
  4. +6 −6 src/yadis.erl
@@ -10,29 +10,29 @@
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).
--record(xrdService, {
+-record(openid_xrdservice, {
types,
uris,
localID
}).
--record(xrds, {
+-record(openid_xrds, {
origID,
claimedID,
canonicalID,
isXRI,
services
}).
--record(authReq, {
+-record(openid_authreq, {
opURLs,
version,
claimedID=none,
localID=none,
assoc=none
}).
--record(assoc, {
+-record(openid_assoc, {
handle,
created,
expiresIn,
View
@@ -20,14 +20,14 @@
discover(Identifier) ->
Req = case yadis:retrieve(Identifier) of
{none, Body} -> html_discovery(Body);
- #xrds{}=XRDS -> extract_authreq(XRDS);
+ #openid_xrds{}=XRDS -> extract_authreq(XRDS);
{error, _Error} ->
%?DBG({error, Error}),
none
end,
case Req of
- #authReq{} -> set_identity_params(Req);
+ #openid_authreq{} -> set_identity_params(Req);
_ -> Req
end.
@@ -45,15 +45,15 @@ authreq_by_opid(XRDS) ->
authreq_by_opid(_, []) -> none;
authreq_by_opid(XRDS, [Type|Rest]) ->
- case find_service(XRDS#xrds.services, Type) of
+ case find_service(XRDS#openid_xrds.services, Type) of
none -> authreq_by_opid(XRDS, Rest);
Service -> build_authReq(XRDS, Service, {2,0})
end.
find_service([], _) -> none;
-find_service([#xrdService{uris=[]}|Rest], Type) -> find_service(Rest, Type);
-find_service([#xrdService{types=Types}=Service|Rest], Type) ->
+find_service([#openid_xrdservice{uris=[]}|Rest], Type) -> find_service(Rest, Type);
+find_service([#openid_xrdservice{types=Types}=Service|Rest], Type) ->
case lists:any(fun(X) -> X == Type end, Types) of
true -> Service;
false -> find_service(Rest, Type)
@@ -68,17 +68,17 @@ authreq_by_claimed_id(XRDS) ->
authreq_by_claimed_id(_, []) ->
none;
authreq_by_claimed_id(XRDS, [{Type,Version}|Rest]) ->
- case find_service(XRDS#xrds.services, Type) of
+ case find_service(XRDS#openid_xrds.services, Type) of
none -> authreq_by_claimed_id(XRDS, Rest);
Service -> build_authReq(XRDS, Service, Version)
end.
build_authReq(XRDS, Service, Version) ->
- #authReq{opURLs=Service#xrdService.uris,
- version=Version,
- claimedID=XRDS#xrds.claimedID,
- localID=Service#xrdService.localID}.
+ #openid_authreq{opURLs=Service#openid_xrdservice.uris,
+ version=Version,
+ claimedID=XRDS#openid_xrds.claimedID,
+ localID=Service#openid_xrdservice.localID}.
html_discovery(Body) ->
@@ -94,7 +94,7 @@ html_discovery(Body, [{ProviderRel, LocalIDRel, Version}|Rest]) ->
none -> html_discovery(Body, Rest);
URL ->
LocalID = html_local_id(Body, LocalIDRel),
- #authReq{opURLs=[URL], version=Version, localID=LocalID}
+ #openid_authreq{opURLs=[URL], version=Version, localID=LocalID}
end;
_ -> html_discovery(Body, Rest)
end.
@@ -107,9 +107,9 @@ html_local_id(Body, RelName) ->
set_identity_params(AuthReq) ->
- {Claimed, Local} = get_identity_params(AuthReq#authReq.claimedID,
- AuthReq#authReq.localID),
- AuthReq#authReq{claimedID=Claimed, localID=Local}.
+ {Claimed, Local} = get_identity_params(AuthReq#openid_authreq.claimedID,
+ AuthReq#openid_authreq.localID),
+ AuthReq#openid_authreq{claimedID=Claimed, localID=Local}.
get_identity_params(none, _) ->
{"http://specs.openid.net/auth/2.0/identifier_select",
@@ -173,11 +173,11 @@ associate(OpURL) ->
MAC = crypto:exor(crypto:sha(ZZ), EncMAC),
- #assoc{handle=Handle,
- created=now(),
- expiresIn=ExpiresIn,
- servPublic=ServPublic,
- mac=MAC}.
+ #openid_assoc{handle=Handle,
+ created=now(),
+ expiresIn=ExpiresIn,
+ servPublic=ServPublic,
+ mac=MAC}.
roll(N) when is_binary(N) ->
@@ -208,23 +208,23 @@ split_kv([C|Rest], Buff) -> split_kv(Rest, [C|Buff]).
authentication_url(AuthReq, ReturnTo, Realm) ->
- Assoc = AuthReq#authReq.assoc,
+ Assoc = AuthReq#openid_authreq.assoc,
- IDBits = case AuthReq#authReq.claimedID of
+ IDBits = case AuthReq#openid_authreq.claimedID of
none -> [];
- _ -> [{"openid.claimed_id", AuthReq#authReq.claimedID},
- {"openid.identity", AuthReq#authReq.localID}]
+ _ -> [{"openid.claimed_id", AuthReq#openid_authreq.claimedID},
+ {"openid.identity", AuthReq#openid_authreq.localID}]
end,
Params = [{"openid.ns", "http://specs.openid.net/auth/2.0"},
{"openid.mode", "checkid_setup"},
- {"openid.assoc_handle", Assoc#assoc.handle},
+ {"openid.assoc_handle", Assoc#openid_assoc.handle},
{"openid.return_to", ReturnTo},
{"openid.realm", Realm}] ++ IDBits,
QueryString = mochiweb_util:urlencode(Params),
- [URL|_] = AuthReq#authReq.opURLs,
+ [URL|_] = AuthReq#openid_authreq.opURLs,
list_to_binary([URL, "?", QueryString]).
@@ -241,7 +241,7 @@ test() ->
?DBG({identifier, ID}),
Req = discover(ID),
%?DBG({request, Req}),
- [URL,_] = Req#authReq.opURLs,
+ [URL,_] = Req#openid_authreq.opURLs,
Assoc = associate(URL),
?DBG({assoc, Assoc}),
%?DBG({auth, authenticate(Req2, "http://dev.brendonh.org/return", "http://dev.brendonh.org/")}),
View
@@ -131,7 +131,7 @@ discover_authreq(Identifier, Cache, State) ->
get_assoc(AuthReq, Cache, State) ->
- [OpURL|_] = AuthReq#authReq.opURLs,
+ [OpURL|_] = AuthReq#openid_authreq.opURLs,
%initiate_assoc(OpURL, Cache, State).
case ets:lookup(State#state.assocs, OpURL) of
[] -> initiate_assoc(OpURL, Cache, State);
@@ -156,10 +156,10 @@ initiate_assoc(OpURL, Cache, State) ->
end.
check_expiry(Assoc, AuthReq, Cache, State) ->
- case timer:now_diff(now(), Assoc#assoc.created) of
- X when X > (Assoc#assoc.expiresIn * 1000000) ->
+ case timer:now_diff(now(), Assoc#openid_assoc.created) of
+ X when X > (Assoc#openid_assoc.expiresIn * 1000000) ->
%?DBG(assoc_expired),
- [OpURL,_] = AuthReq#authReq.opURLs,
+ [OpURL,_] = AuthReq#openid_authreq.opURLs,
initiate_assoc(OpURL, Cache, State);
_ ->
Assoc
@@ -170,7 +170,7 @@ pend_login(UUID, AuthReq, Assoc, State) ->
%?DBG({pending, UUID, AuthReq, Assoc#assoc.handle}),
ets:insert(State#state.pending, {UUID, {AuthReq, Assoc}}),
timer:send_after(?PENDING_TIMEOUT * 1000, {invalidate_pending, UUID}),
- AuthReq#authReq{assoc=Assoc}.
+ AuthReq#openid_authreq{assoc=Assoc}.
%%--------------------------------------------------------------------
@@ -187,7 +187,7 @@ verify_discovered(UUID, Fields, State) ->
GivenHandle = ?GV("openid.assoc_handle", Fields),
case ets:lookup(State#state.pending, UUID) of
[] -> {error, "No pending login"};
- [{UUID, {AuthReq, #assoc{handle=GivenHandle}=Assoc}}] ->
+ [{UUID, {AuthReq, #openid_assoc{handle=GivenHandle}=Assoc}}] ->
verify_claimed_id(AuthReq, Assoc, Fields, State);
_OtherAssoc -> {error, "Invalid association handle"}
end.
@@ -196,13 +196,13 @@ verify_claimed_id(AuthReq, Assoc, Fields, State) ->
case ?GVD("openid.claimed_id", Fields, none) of
none -> {error, "No claimed identifier"};
ClaimedID ->
- case AuthReq#authReq.claimedID of
+ case AuthReq#openid_authreq.claimedID of
ClaimedID ->
verify_nonce(ClaimedID, Assoc, Fields, State);
OtherID ->
DiscoveredReq = get_authreq(ClaimedID, false, State),
- [OpURL|_] = AuthReq#authReq.opURLs,
- case lists:any(fun(X) -> X == OpURL end, DiscoveredReq#authReq.opURLs) of
+ [OpURL|_] = AuthReq#openid_authreq.opURLs,
+ case lists:any(fun(X) -> X == OpURL end, DiscoveredReq#openid_authreq.opURLs) of
true -> verify_nonce(OtherID, Assoc, Fields, State);
false -> {error, "Invalid OP endpoint discovered"}
end
@@ -246,10 +246,10 @@ verify_signature(ClaimedID, Assoc, Fields) ->
verify_signature(_, _, none, _Fields) ->
{error, "Direct verification not implemented yet"};
-verify_signature(_ClaimedID, false, #assoc{}=Assoc, Fields) ->
+verify_signature(_ClaimedID, false, #openid_assoc{}=Assoc, Fields) ->
KV = lists:flatten([[Key,$:,?GV("openid." ++ Key, Fields),$\n]
|| Key <- string:tokens(?GV("openid.signed", Fields), ",")]),
- MAC = Assoc#assoc.mac,
+ MAC = Assoc#openid_assoc.mac,
Sig = crypto:sha_mac(MAC, KV),
GivenSig = base64:decode(?GV("openid.sig", Fields)),
View
@@ -53,7 +53,7 @@ retrieve(Identifier) ->
case XRDS of
none ->
{none, Body};
- #xrds{} ->
+ #openid_xrds{} ->
% XXX Todo -- Normalize DescriptorURL as claimedID
% (2.0 spec #7.2.4)
@@ -62,9 +62,9 @@ retrieve(Identifier) ->
true -> Normalized;
false -> DescriptorURL
end,
- XRDS#xrds{origID=Identifier,
- isXRI=IsXRI,
- claimedID=ClaimedID}
+ XRDS#openid_xrds{origID=Identifier,
+ isXRI=IsXRI,
+ claimedID=ClaimedID}
end;
Other ->
{error, {http_error, {Normalized, Other}}}
@@ -138,7 +138,7 @@ munge_xrds(String) ->
Services = [S || {_P, S} <- lists:sort(
fun({P1,_},{P2,_}) -> P1 < P2 end,
[munge_service(S) || S <- xmerl_xpath:string("XRD/Service", Doc)])],
- #xrds{canonicalID=CanonicalID, services=Services}.
+ #openid_xrds{canonicalID=CanonicalID, services=Services}.
munge_service(Service) ->
Priority = get_priority(Service#xmlElement.attributes),
@@ -148,7 +148,7 @@ munge_service(Service) ->
fun({P1,_},{P2,_}) -> P1 < P2 end,
[{get_priority(U#xmlElement.attributes), get_text(U)}
|| U <- xmerl_xpath:string("URI", Service)])],
- {Priority, #xrdService{types=Types, uris=URIs, localID=LocalID}}.
+ {Priority, #openid_xrdservice{types=Types, uris=URIs, localID=LocalID}}.
get_text(#xmlElement{content=[]}) -> "";
get_text(#xmlElement{content=[Value|_]}) -> Value#xmlText.value.

0 comments on commit faa0e47

Please sign in to comment.