views:

192

answers:

1

Hi folks,

i'm trying to set up my code to request some attributes from the OpenID Service Provider. At the same time, I wish to return an ActionResult.

Here's the code in the OpenId sample MVC project (that comes straight out of the DotNetOpenId / DotNetOpenAuth website) ...

try
{
    return openid.CreateRequest(Request.Form["openid_identifier"])
        .RedirectingResponse
        .AsActionResult();
 }
 catch (ProtocolException ex)
 { ... }

This is great, but it doesn't show me requesting any optional or required attributes. So, I've tried the following (my own, untested pseduo-ish code) ....

var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Alias);
fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.Language);
fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.TimeZone);
fetch.Attributes.AddRequired(WellKnownAttributes.Person.Gender);

openId.CreateRequest(identifier.ToString()).AddExtension(fetch);

This also seems fine. But ... i don't know how to now ask for the result to be an ActionResult()...

How can i create an openId.CreateRequest that allows me to define some required attributes AND return an ActionView ?

+1  A: 

You're doing great. Just combine the two approaches.

After you call IAuthenticationRequest.AddExtension all you want, just call IAuthenticationRequest.RedirectingResponse.AsActionResult().

try
{
    var request = openid.CreateRequest(Request.Form["openid_identifier"]);

    var fetch = new FetchRequest();
    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
    fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
    fetch.Attributes.AddRequired(WellKnownAttributes.Name.Alias);
    fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.Language);
    fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.TimeZone);
    fetch.Attributes.AddRequired(WellKnownAttributes.Person.Gender);
    request.AddExtension(fetch);

    return request.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{ ... }
Andrew Arnott
hmm. That's what i thought (and tried originally) but intellisense was showing an error. My code is at home, so i'll check it out tonight. I'm also sure i'm using the most recent version, also. Cheers again Andrew :)
Pure.Krome
yep - works! i swear i tried that :( heh! the downside of midnight programming ... :)
Pure.Krome