Exemplo n.º 1
0
        // This URL is registered as the application's callback at http://dev.twitter.com
        public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
        {
            var requestToken = new OAuthRequestToken { Token = oauth_token };

            // Step 3 - Exchange the Request Token for an Access Token
            TwitterService service = new TwitterService(AuthenticationTokens.TwitterConsumerKey, AuthenticationTokens.TwitterConsumerSecret);
            OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);

            //Store the access token and secret and create a new user account
            TwitterAuthentication authentication = new TwitterAuthentication()
                                                    {
                                                        AccessToken = accessToken.Token,
                                                        AccessTokenSecret = accessToken.TokenSecret
                                                    };

            //Authenticate account with twitter
            service.AuthenticateWith(AuthenticationTokens.TwitterConsumerKey,
                                        AuthenticationTokens.TwitterConsumerSecret,
                                        authentication.AccessToken, authentication.AccessTokenSecret);

            TwitterUser twitterUser = service.VerifyCredentials();

            ServiceLayer.UserDetailsService.AuthenticateTwitterAccount(authentication, twitterUser.ScreenName,
                                                                       twitterUser.Id);

            //store the credentials in forms auth?
            var authTicket = new FormsAuthenticationTicket(1, twitterUser.ScreenName, DateTime.Now,
                                                 DateTime.Now.AddMonths(6), true, "");

            string cookieContents = FormsAuthentication.Encrypt(authTicket);
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieContents)
            {
                Expires = authTicket.Expiration,
                Path = FormsAuthentication.FormsCookiePath
            };

            if (HttpContext != null)
            {
                HttpContext.Response.Cookies.Add(cookie);
            }

            //new {authentication.AccessToken, authentication.AccessTokenSecret, twitterUser.ScreenName}
            return RedirectToAction("UserProfile");
        }
Exemplo n.º 2
0
 public TwitterStreamRetriever(TwitterAuthentication authentication)
 {
     this._authentication = authentication;
 }