Skip to content

Commit

Permalink
Set claimed identifier when doing HTML discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtj committed Oct 30, 2010
1 parent 25598b2 commit 4089879
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/openid.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

discover(Identifier) ->
Req = case yadis:retrieve(Identifier) of
{none, Body} -> html_discovery(Body);
{none, NormalizedId, Body} -> html_discovery(NormalizedId, Body);
#openid_xrds{}=XRDS -> extract_authreq(XRDS);
{error, _Error} ->
%?DBG({error, Error}),
Expand Down Expand Up @@ -81,22 +81,22 @@ build_authReq(XRDS, Service, Version) ->
localID=Service#openid_xrdservice.localID}.


html_discovery(Body) ->
html_discovery(Body, [{"openid2.provider", "openid2.local_id", {2,0}},
{"openid.server", "openid.delegate", {1,1}}]).
html_discovery(Id, Body) ->
html_discovery(Id, Body, [{"openid2.provider", "openid2.local_id", {2,0}},
{"openid.server", "openid.delegate", {1,1}}]).

html_discovery(_, []) ->
html_discovery(_Id, _, []) ->
none;
html_discovery(Body, [{ProviderRel, LocalIDRel, Version}|Rest]) ->
html_discovery(Id, Body, [{ProviderRel, LocalIDRel, Version}|Rest]) ->
case openid_utils:get_tags(Body, "link", "rel", ProviderRel) of
[Tag|_] ->
case ?GVD("href", Tag, none) of
none -> html_discovery(Body, Rest);
URL ->
LocalID = html_local_id(Body, LocalIDRel),
#openid_authreq{opURLs=[URL], version=Version, localID=LocalID}
#openid_authreq{opURLs=[URL], version=Version, localID=LocalID, claimedID=Id}
end;
_ -> html_discovery(Body, Rest)
_ -> html_discovery(Id, Body, Rest)
end.

html_local_id(Body, RelName) ->
Expand Down
2 changes: 1 addition & 1 deletion src/yadis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ retrieve(Identifier) ->
XRDS = handle_response(DescriptorURL, Headers, Body),
case XRDS of
none ->
{none, Body};
{none, Normalized, Body};
#openid_xrds{} ->

% XXX Todo -- Normalize DescriptorURL as claimedID
Expand Down
8 changes: 4 additions & 4 deletions test/openid_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ discover2_test_() ->
{"http://flickr.com/exbrend",
#openid_authreq{opURLs = ["https://open.login.yahooapis.com/openid/op/auth"],
version = {2,0},
claimedID = "http://specs.openid.net/auth/2.0/identifier_select",
localID = "http://specs.openid.net/auth/2.0/identifier_select",
claimedID = "http://flickr.com/exbrend",
localID = "http://flickr.com/exbrend",
assoc = none}}
],
{setup, fun setup/0, [?_assertEqual(Result, openid:discover(URL))
Expand All @@ -27,8 +27,8 @@ discover1_test_() ->
Cases = [{"blog.paulbonser.com",
#openid_authreq{opURLs = ["http://www.livejournal.com/openid/server.bml"],
version = {1,1},
claimedID = "http://specs.openid.net/auth/2.0/identifier_select",
localID = "http://specs.openid.net/auth/2.0/identifier_select",
claimedID = "http://blog.paulbonser.com/",
localID = "http://misterpib.livejournal.com/",
assoc = none}}
],
{setup, fun setup/0, [?_assertEqual(Result, openid:discover(URL))
Expand Down
2 changes: 1 addition & 1 deletion test/yadis_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ retrieve_test_() ->
#openid_xrds{origID = "=brendonh",claimedID = "=brendonh",
canonicalID = none,isXRI = true,services = []}}
],
{setup, fun setup/0, [?_assertEqual(Result, yadis:retrieve(URL))
{setup, fun setup/0, [?_test(?_assertEqual(Result, yadis:retrieve(URL)))
|| {URL, Result} <- Cases ]}.

0 comments on commit 4089879

Please sign in to comment.