OAuth Functionality
예제 #1
0
        public ActionResult Index(string code)
        {
            try
            {
                // Check for a token in the session already, and if found, no action is required
                if (!string.IsNullOrEmpty(SessionInfo.Current.AccessToken))
                    return RedirectToAction("Index", "Home");

                // Init oAuth
                var oAuth = new OAuth();

                // We get a code back from the first leg of OAuth process.  If we don't have one, let's get it.
                if (string.IsNullOrEmpty(code))
                {
                    string authorizationUrl = oAuth.GetAuthorizationUrl();
                    return Redirect(authorizationUrl);
                }

                // Otherwise, we have a code, we can run the second leg of OAuth process.
                var authorization = oAuth.CallAuthorization(null, code);

                // OAuth successful so get values, store in session and continue
                if (authorization.Success)
                {
                    // Authorization successful; set session variables
                    SessionInfo.Current.AccessToken = authorization.AccessToken;
                    SessionInfo.Current.FullName = authorization.UserFullName;
                    SessionInfo.Current.Roles = authorization.UserSLIRoles;
                    SessionInfo.Current.UserId = authorization.UserId;

                    // Redirect to post login URL if one exists
                    if (!string.IsNullOrEmpty(SessionInfo.Current.PostLoginRedirectUrl))
                    {
                        var returnUrl = SessionInfo.Current.PostLoginRedirectUrl;
                        SessionInfo.Current.PostLoginRedirectUrl = null;
                        return Redirect(returnUrl);
                    }

                    // Otherwise, just go to home
                    return RedirectToAction("Index", "Home", SessionInfo.Current.SPContextRouteValues);
                }

                return Content("Unknown Error authorizing");
            }
            catch (Exception ex)
            {
                return Content("Error authorizing: " + ex.Message);
            }
        }
예제 #2
0
 //public ActionResult About()
 //{
 //    ViewBag.Message = "Your application description page.";
 //    return View();
 //}
 //public ActionResult Contact()
 //{
 //    ViewBag.Message = "Your contact page.";
 //    return View();
 //}
 public RedirectResult Login()
 {
     var auth = new OAuth();
     return Redirect(auth.GetAuthorizationUrl());
 }