代码之家  ›  专栏  ›  技术社区  ›  LiamB

dotnetopenid-open id获取一些数据

  •  1
  • LiamB  · 技术社区  · 15 年前

    我正在一个新的网站上使用OpenID,并试图获得关于用户的一些基本信息,请参见下面的代码。为什么下面的allways为空?

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

    以及主代码

    [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 回复  |  直到 13 年前
    推荐文章