예제 #1
0
        public ActionResult OpenId(Login model)
        {
            Identifier id;
            if (Identifier.TryParse(model.OpenID_Identifier, out id))
            {
                try
                {
                    var openId = new OpenIdRelyingParty();
                    var returnToUrl = new Uri(Url.Action("OpenIdCallback", "Authentication", new { ReturnUrl = model.ReturnUrl }, Request.Url.Scheme), UriKind.Absolute);
                    var request = openId.CreateRequest(id, Realm.AutoDetect, returnToUrl);

                    request.AddExtension(new ClaimsRequest
                    {
                        Email = DemandLevel.Require,
                        FullName = DemandLevel.Require,
                        Nickname = DemandLevel.Require
                    });

                    // also add AX request
                    var axRequest = new FetchRequest();
                    axRequest.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
                    axRequest.Attributes.AddRequired(WellKnownAttributes.Name.First);
                    axRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last);
                    axRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
                    request.AddExtension(axRequest);

                    return request.RedirectingResponse.AsActionResult();
                }
                catch (ProtocolException ex)
                {
                    model.Message = ex.Message;
                    return View("Login", model);
                }
            }
            else
            {
                model.Message = "Invalid identifier";
                return View("Login", model);
            }
        }
예제 #2
0
        public ActionResult OpenIdCallback(string returnUrl)
        {
            var model = new Login { ReturnUrl = returnUrl };
            var openId = new OpenIdRelyingParty();
            var openIdResponse = openId.GetResponse();

            if (openIdResponse.Status == AuthenticationStatus.Authenticated)
            {
                var friendlyName = GetFriendlyName(openIdResponse);

                var isPersistentCookie = true;
                SetAuthCookie(openIdResponse.ClaimedIdentifier, isPersistentCookie, friendlyName);

                return Redirect(returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home"));
            }

            model.Message = "Sorry, login failed.";
            return View("Login", model);
        }
예제 #3
0
 public ActionResult Login(string returnUrl)
 {
     var model = new Login { ReturnUrl = returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home") };
     return View(model);
 }