开发者

null ClaimsResponse with DotNetOpenAuth in ASP.NET MVC 2 application

开发者 https://www.devze.com 2023-01-13 02:28 出处:网络
I\'m trying to get DotNetOpenAuth (latest version) to work with ASP.NET MVC 2 website. I get the first part working, the action is invoked when user selects OpenID provider, I get correct identifier p

I'm trying to get DotNetOpenAuth (latest version) to work with ASP.NET MVC 2 website. I get the first part working, the action is invoked when user selects OpenID provider, I get correct identifier passed in, I then get correctly redirected to the provider website, I get redirected back to my website but here's the problem.

The claims I requested are null (see the code below).

public ActionResult TryAuth(string openid_identifier)
{
    var openid = new OpenIdRelyingParty();
    var response = openid.GetResponse();
    if(response== null)
    {
        var req = openid.CreateRequest(openid_identifier);
        req.AddExtension(new ClaimsRequest
                            {
                                Email = DemandLevel.Require,
                                Nickname = DemandLevel.Require
                            });
        return req.RedirectingResponse.AsActionResult();
    }
    switch(response.Status)
    {
        case AuthenticationStatus.Authenticated:
            {
                var data = response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
                // data is null <-----------------------------------------
                re开发者_运维技巧turn View("Index");
            }
    }
    return View("Index");
}

I would greatly appreciate if anyone can point out the (not so) obvious mistake I'm making.


I had the same issue until I discovered that for Google you have to set the email field to DomainLevel.Require instead of DomainLevel.Request (Optional)

fields.Email = DemandLevel.Require;


Please look through all the similar questions.Refer this

Your code looks fine. Make sure you activate the AXFetchAsSregTransform in your web.config file though to maximize the chance of you getting something back. It's up to the Provider to give you any attributes though. Some Providers like Yahoo require that your RP correctly implement RP Discovery, which the sample RPs that come with DotNetOpenAuth demonstrate.

Here is my blog post on getting RP Discovery done right. Do this, and try the sites you've been testing against again. Keep in mind as well that some Providers cache RP Discovery results, so you might apply all your RP Discovery fixes, and still have to wait an hour or a day before the Providers start giving you data.

0

精彩评论

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