开发者

No email is returned upon a successful OpenID login with DotNetOpenAuth ASP.NET MVC Login sample

I have extended DotNetOpenAuth ASP.NET MVC Login sample while trying to get at least an email from the OpenID provider. No matter which provider I use to log in, I get null for ClaimsResponse. Here is the code.

var request = openid.CreateRequest(Request.Form["OpenID"]);
// Require some additional data
request.AddExtension(new ClaimsRequest
                            {
                                Email = DemandLevel.Require,
                            });
return request.RedirectingResponse.AsActionResult();

And this is the snippet to get the ClaimsResponse:

switch (response.Status)
{
    case AuthenticationStatus.Authenticated:
        var claimsResponse = response.GetExtension<ClaimsResponse>();
        // This is null!
        break;
}

Before trying this on the MVC sample, I have done the same on WebForms sample and got back the requested email! But this is really hard to get wrong as OpenID related code is virtually the same.

I have noticed that generated OpenID URLs differ in the following: openid.ns.alias3=http://openid.net/srv/ax/1.0&openid.alias3.required=alias1,alias2,alias3,alias4&openid.alias3.mode=fetch_request&openid.alias3.type.alias1=http://axschema.org/contact/email&openid.alias3.count.alias1=1&openid.alias3.type.alias2=http://axschema.org/namePerson&openid.alias3.count.alias2=1&openid.alias3.type.alias3=http://schema.openid.net/contact/email&openid.alias3.count.alias3=1&openid.alias3.type.alias4=http://schema.openid.net/namePerson&openid.alias3.count.alias4=1. Basically, the WebForms version generates an URL with all of that appended while the MVC URL lacks this. The net effect is that email is presented to WebForms while there is none for a MVC app.

One last thing I noticed is that e.g. Google shows as if re开发者_开发问答quest comes from localhost for a WebForms app and 127.0.0.1 for a MVC app. Maybe that makes all the difference. Still, I am not sure if I am in control here.

The thing that bothers me is that the code is the same for both projects. Still the URLs generated are different and MVC gets no email.


It sounds like your web forms site has the AXFetchAsSreg behavior activated but your MVC one does not. Activate it for your MVC site and you should be good.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜