OpenID Immediate Request

4 views
Skip to first unread message

Spines

unread,
Feb 2, 2010, 2:16:34 PM2/2/10
to dyuproject
How do I do an immediate request with the dyuproject OpenID? I want
to store the user's openid url in a long living cookie, and then use
an immediate request to authenticate the user next time they visit, as
described in the OpenID Relying Party Best Practices document (http://
wiki.openid.net/Relying-Party-Best-
Practices#StoreprimaryOpenIDinacookieandcheckimmediateatnextsession)

David Yu

unread,
Feb 2, 2010, 11:22:04 PM2/2/10
to dyuproject
Try the ff:

// note that the claimedId and the openIdServer should be
persisted in the cookie.
OpenIdUser user = getStoredOpenIdUserFromCookie(request);
assert(user!=null);

OpenIdContext context = relyingParty.getOpenIdContext();
boolean associated = context.getAssociation().associate(user,
context);
assert(associated);

StringBuffer url = request.getRequestURL();
String trustRoot = url.substring(0, url.indexOf("/", 9));
String realm = url.substring(0, url.lastIndexOf("/"));
UrlEncodedParameterMap params = RelyingParty.getAuthUrlMap
(trustRoot, realm, returnTo);

HttpConnector connector = context.getHttpConnector();
HttpConnector.Response r = connector.doGET(params.getUrl(),
(Map<?,?)null, params);

// parse the response
Map<String,String> responseMap = parse(r.getInputStream());
if("setup_needed".equals(responseMap.get("openid.mode")))
{
// redirect the user
response.sendRedirect(responseMap.get("user_setup_url"));
return;
}

// user is authenticated


Let me know if there are any errors.

Cheers

David Yu

unread,
Feb 2, 2010, 11:24:33 PM2/2/10
to dyuproject
Oh and before doing the connector.doGET, override the mode:
params.put("openid.mode", "checkid_immediate");

David Yu

unread,
Feb 3, 2010, 12:51:35 AM2/3/10
to dyuproject
Disregard the last comments, I just tried this myself (with a lot of
modifications), i've been getting "setup_needed".
I'll try to look around for answers.

Spines

unread,
Feb 3, 2010, 12:58:02 PM2/3/10
to dyuproject
I noticed in RelyingParty.java - getAuthUrlMap, the line

map.put(Constants.OPENID_MODE, Constants.Mode.CHECKID_SETUP);

Seems that the mode is hard coded to setup, maybe allow the mode to be
passed into the method?


Also, have you tried the library with yahoo openid? I'm getting an
error of some sort. I haven't looked much into it though, so it might
be something in my code and not your library.

Reply all
Reply to author
Forward
0 new messages