コード例 #1
0
        public async Task<ActionResult> CompleteAsync()
        {
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };

            await auth.CompleteAuthorizeAsync(Request.Url);

            // This is how you access credentials after authorization.
            // The oauthToken and oauthTokenSecret do not expire.
            // You can use the userID to associate the credentials with the user.
            // You can save credentials any way you want - database, 
            //   isolated storage, etc. - it's up to you.
            // You can retrieve and load all 4 credentials on subsequent 
            //   queries to avoid the need to re-authorize.
            // When you've loaded all 4 credentials, LINQ to Twitter will let 
            //   you make queries without re-authorizing.
            //
            //var credentials = auth.CredentialStore;
            //string oauthToken = credentials.OAuthToken;
            //string oauthTokenSecret = credentials.OAuthTokenSecret;
            //string screenName = credentials.ScreenName;
            //ulong userID = credentials.UserID;
            //

            return RedirectToAction("Index", "Home");
        }
コード例 #2
0
        public async Task<ActionResult> CompleteAsync()
        {
            if (Request.QueryString["serviceInterval"] != null)
            {
                ServiceInterval = Convert.ToInt32(Request.QueryString["serviceInterval"]);
            }
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore
                {
                    ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"].ToString(),
                    ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"].ToString()
                }
            };

            await auth.CompleteAuthorizeAsync(Request.Url);
            //
            Profile model = new Data.Models.Profile();
            var credentials = auth.CredentialStore;
            model.AccessToken = credentials.OAuthToken;
            model.TokenSecret = credentials.OAuthTokenSecret;
            model.Username = credentials.ScreenName;
            model.UserId = credentials.UserID.ToString();
            model.ProfileTypeID = 3;
            model.Interval = ServiceInterval;
            SaveTwitterInfo(model);
            return RedirectToAction("Index", "Profile");
        }
コード例 #3
0
        public async Task<ActionResult> CompleteAsync(string returnUrl)
        {
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };

            await auth.CompleteAuthorizeAsync(Request.Url);

            //save credentials in cookie
            var credentials = auth.CredentialStore;
            Cookies.Write(Response, "TwitterOAuthToken", credentials.OAuthToken);
            Cookies.Write(Response, "TwitterOAuthTokenSecret", credentials.OAuthTokenSecret);
            Cookies.Write(Response, "TwitterScreenName", credentials.ScreenName);
            Cookies.Write(Response, "TwitterUserID", credentials.UserID.ToString());

            return Redirect(returnUrl);
        }
コード例 #4
0
        //
        // GET: /Account/LogOn

        public async Task<ActionResult> LogOn(bool complete = false)
        {
            //return View();
            if (!Request.IsAuthenticated)
            {
                if (complete)
                {
                    var auth = new MvcAuthorizer
                    {
                        CredentialStore = new SessionStateCredentialStore()
                    };

                    await auth.CompleteAuthorizeAsync(Request.Url);

                    FormsAuthentication.SetAuthCookie(auth.CredentialStore.ScreenName, true);
                    PostworthyUser pm = UsersCollection.Single(auth.CredentialStore.ScreenName, force: true, addIfNotFound: true);
                    if (string.IsNullOrEmpty(pm.AccessToken) && string.IsNullOrEmpty(pm.OAuthToken))
                    {
                        pm.AccessToken = auth.CredentialStore.OAuthTokenSecret;
                        pm.OAuthToken = auth.CredentialStore.OAuthToken;
                        UsersCollection.Save();
                    }

                    return RedirectToAction("Index", new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional });
                }
                else
                {
                    //var auth = new MvcSignInAuthorizer
                    var auth = new MvcAuthorizer
                    {
                        CredentialStore = new SessionStateCredentialStore
                        {
                            ConsumerKey = ConfigurationManager.AppSettings["TwitterCustomerKey"],
                            ConsumerSecret = ConfigurationManager.AppSettings["TwitterCustomerSecret"]
                        }
                    };
                    string twitterCallbackUrl = Request.Url.ToString() + "?complete=true";
                    return await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl));
                }
            }
            else
                return RedirectToAction("Index", new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional });
        }