DotNetOpenId - Open Id get some data

做~自己de王妃 提交于 2019-12-02 11:14:07

问题


I'm using OpenId on a new website and am trying to get some basic information about the user, see the code below. Why is the following allways null?

var myData = response.GetExtension<ClaimsResponse>();

And the main code

[System.Web.Mvc.AcceptVerbs(HttpVerbs.Get)]
    public ActionResult LogOn()
    {
        var openid = new OpenIdRelyingParty();
        IAuthenticationResponse response = openid.GetResponse();

        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    FormsAuthentication.RedirectFromLoginPage(
                        response.ClaimedIdentifier, false);
                    var myData = response.GetExtension<ClaimsResponse>();
                    break;
                case AuthenticationStatus.Canceled:
                    ModelState.AddModelError("loginIdentifier",
                        "Login was cancelled at the provider");
                    break;
                case AuthenticationStatus.Failed:
                    ModelState.AddModelError("loginIdentifier", 
                        "Login failed using the provided OpenID identifier");
                    break;
            }
        }



        return View("Register");
    }

    [System.Web.Mvc.AcceptVerbs(HttpVerbs.Post)]
    public ActionResult LogOn(string loginIdentifier)
    {
        if (!Identifier.IsValid(loginIdentifier))
        {
            ModelState.AddModelError("loginIdentifier",
                        "The specified login identifier is invalid");
            return View();
        }
        else
        {
            var openid = new OpenIdRelyingParty();
            IAuthenticationRequest request = openid.CreateRequest(
                Identifier.Parse(loginIdentifier));

            // Require some additional data
            request.AddExtension(new ClaimsRequest
            {
                Email = DemandLevel.Request,
                FullName = DemandLevel.Request
            });

            return request.RedirectingResponse.AsActionResult();
        }
    }

回答1:


http://www.dotnetopenauth.net/developers/help/the-axfetchassregtransform-behavior/



来源:https://stackoverflow.com/questions/1593506/dotnetopenid-open-id-get-some-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!