Beispiel #1
0
        public ActionResult HandleFacebookOAuthCallback(string code, string state)
        {
            if (code.IsNullOrWhiteSpace())
            {
                return(this.RedirectToAction(c => c.Login()));
            }

            // TODO, decrypt redirectURL
            var redirectURL = string.Empty;

            if (!string.IsNullOrWhiteSpace(state))
            {
                redirectURL = HttpUtility.UrlDecode(state);
            }

            var facebookAccessToken = FacebookAuthentication.ExchangeCodeForAccessToken(Request, FacebookAuthenticationOptions.FromWebConfig(), code);

            var user = DatabaseSession.Query <UserAccount>().Where(x => x.FacebookId == facebookAccessToken.FacebookID).SingleOrDefault();

            if (user == null)
            {
                user = new UserAccount(facebookAccessToken);
                // TODO: redirect to a welcome page to confirm info redirectURL = this.GetURL<>
            }
            user.UpdateSeen();
            var tokenEntity = user.AddFacebookAccessToken(facebookAccessToken);

            DatabaseSession.Save(user);
            DatabaseSession.Flush();
            var tokenID = tokenEntity.UserFacebookAccessTokenId;

            HttpContext.Get <IAuthenticationManager>().SignIn(tokenID.ToString(), FacebookAuthentication.AuthenticationType);

            if (redirectURL.IsNullOrWhiteSpace())
            {
                redirectURL = "~";
            }
            return(Redirect(redirectURL));
        }
Beispiel #2
0
        public ActionResult FacebookOAuthChallenge(string redirectUrl = "")
        {
            var url = FacebookAuthentication.GetAuthChallengeURL(Request, FacebookAuthenticationOptions.FromWebConfig());

            return(Redirect(url));
        }