public IHttpActionResult RegisterExternal(string state)
        {
            ApplicationUserLogin userLogin;

            state = state.ToLower();

            if (state == "facebook")
            {
                var token = FacebookAuthenticator.RetrieveAccessToken(GetQueryString(this.Request, "code"));
                userLogin = FacebookAuthenticator.CreateUserLogin(token);
            }
            else if (state == "google")
            {
                var token = GoogleAuthenticator.RetrieveAccessToken(GetQueryString(this.Request, "code"));
                userLogin = GoogleAuthenticator.CreateUserLogin(token);
            }
            else if (state == "twitter")
            {
                var authToken    = GetQueryString(this.Request, "oauth_token");
                var authVerifier = GetQueryString(this.Request, "oauth_verifier");

                userLogin = TwitterAuthenticator.CreateUserLogin(authToken, authVerifier);
            }
            else
            {
                return(this.BadRequest());
            }

            var result    = this._userRepo.CreateExternalUser(userLogin);
            var userToken = ApplicationUserManager.CreateToken(result.User);

            // Returns the user token in text/plain format to help our deficient friend IE
            var resp = this.Request.CreateResponse();

            resp.Content = new StringContent(userToken, Encoding.UTF8, "text/plain");

            if (result.UserCreated)
            {
                resp.StatusCode = HttpStatusCode.Created;
                return(this.ResponseMessage(resp));
            }

            resp.StatusCode = HttpStatusCode.OK;

            return(this.ResponseMessage(resp));
        }
        void ShowTwitterAuthenticationFlow()
        {
            var auth = TwitterAuthenticator.GetTwitterAuthenticator((bool sucessful) =>
            {
                //dismisses twitter dialog
                DismissViewController(true, () =>
                {
                    if (sucessful)
                    {
                        var popToViewController = NavigationController.ViewControllers.Where(c => c.GetType() == typeof(MyOutletsViewController)).First();
                        NavigationController.PopToViewController(popToViewController, true);
                    }
                });
            });
            var ui = auth.GetUI();

            PresentViewController(ui, true, null);
        }
    public IEnumerator SendData(string logString, string stackTrace, string type)
    {
        TwitterAuthenticator Authenticator = null;
        TwitterInteractor    Interactor    = null;

        if (Authenticator == null)
        {
            Authenticator = TwitterAuthenticator.Instance;
        }

        Debug.Log("have authenticator.");

        // See if the accesstoken and access secret have already been entered before
        string accesstoken  = PlayerPrefs.GetString("Access Token");
        string accessSecret = PlayerPrefs.GetString("Access Secret");

        // If the access token and access secret have been set before, then load them back into the API
        if (!string.IsNullOrEmpty(accesstoken) && !string.IsNullOrEmpty(accessSecret))
        {
            // Set the tokens to the previously received tokens
            Authenticator.setTokens(accesstoken, accessSecret);
            Interactor = new TwitterInteractor(Authenticator);
        }

        Debug.Log("Logging to google forms.");
        WebClient client = new WebClient();

        var keyValue = new NameValueCollection();

        keyValue.Add("entry.1996553891", Interactor.getLoggedInUserScreenName()); // twitter screename
        keyValue.Add("entry.4768965464", Interactor.getCurrentUser());            // full name
        keyValue.Add("entry.1696860947", stackTrace);                             // stack trace
        keyValue.Add("entry.441305901", logString);                               // error condition
        keyValue.Add("entry.174248846", DateTime.Now.ToString());                 // error date and tiem
        keyValue.Add("entry.736989736", type.ToString());                         // error type

        Uri uri = new Uri("https://docs.google.com/forms/d/e/1FAIpQLSfhhipZz7EgdRDacPna2m-gOnV97phLahegPhWcmJdRgD2SEA/formResponse");

        byte[] response = client.UploadValues(uri, "POST", keyValue);
        yield return(Encoding.UTF8.GetString(response));
    }
示例#4
0
        public ActionResult GetRequestToken()
        {
            twOAuth = new TwitterAuthenticator(
                // real consumer key
                "VPV4S0Yly38DQGCnjzAJQ",
                // fake consumer key
                //"cChZNFj6T5R0TigYB9yd1w",

                // real consumer secret
                "fg99T7lvSoAXLBcW0eqgPVcAHQHlWEKEso2WBP7E4lA",
                // fake consumer secret
                //"L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg",

                // real callback
                "http://mysite.ru:1083/Login/TwitterCallback/"
                // face callback
                //"http://localhost/sign-in-with-twitter/"
                );

            requestTokenResult = twOAuth.GetRequestToken();

            return(new RedirectResult(twOAuth.UserAuthorizationUrl));
        }
        public async Task Test_TwitterController_TwitterAuth_Fail()
        {
            //Arrange

            //Twitter Client returns IsAuthenticated false
            this.MockTwitterClient = this.InitMockTwitterClient(this.SecuritySettings, false);

            TwitterAuthModel facebookAuthModel = new TwitterAuthModel
            {
                APIKey = "<api key>"
            };

            TwitterAuthenticator authenticator = new TwitterAuthenticator(this.SecuritySettings.TwitterSecuritySettings,
                                                                          this.MockTwitterClient.Object);

            var controller = new TwitterController(authenticator);

            //Act
            var result = await controller.Create(facebookAuthModel);

            //Assert
            Assert.IsType <BadRequestResult>(result);
            this.MockTwitterClient.Verify(x => x.PostSecurityRequest(), Times.Once);
        }
示例#6
0
 public HomeTimelineNavigatable(TwitterAuthenticator authenticator) : base(authenticator)
 {
     twitterObjects = new List <Status>();
 }
示例#7
0
 public DMUsersNavigatable(TwitterAuthenticator authenticator) : base(authenticator)
 {
     twitterObjects = new List <User>();
 }
    public void initializeAuthComponent()
    {
        if (Authenticator == null)
        {
            try
            {
                Authenticator = TwitterAuthenticator.Instance;
            }
            catch (Exception e)
            {
                Debug.Log(e.StackTrace);
                checkErrorCodes(e);
            }
        }

        if (Authenticator == null)
        {
            DisplayManager.PushNotification("Something went wrong with your twitter authentication. If this persists please contact the development team.");
            navigateToTwitterAuthPage("Authenticator is null");
        }

        // See if the accesstoken and access secret have already been entered before
        string accesstoken  = PlayerPrefs.GetString("Access Token");
        string accessSecret = PlayerPrefs.GetString("Access Secret");

        // If the access token and access secret have been set before, then load them back into the API
        if (Remember && !string.IsNullOrEmpty(accesstoken) && !string.IsNullOrEmpty(accessSecret))
        {
            // Set the tokens to the previously received tokens
            makeTwitterAPICallNoReturnVal(() => Authenticator.setTokens(accesstoken, accessSecret));
            try
            {
                Interactor = new TwitterInteractor(Authenticator);
            }
            catch (Exception e)
            {
                Debug.Log(e.StackTrace);
                checkErrorCodes(e);
            }

            if (Interactor == null)
            {
                DisplayManager.PushNotification("Something went wrong with your twitter authentication. If this persists please contact the development team.");
                navigateToTwitterAuthPage("Interactor is null");
            }

            // Recover from errors having to do with exceptions in home timeline thread
            Interactor.getHomeTimelineNavigatable().OnExp = exception =>
            {
                Debug.Log(exception.Message.ToString());
                Crashlytics.RecordCustomException("Twitter Exception", "thrown exception", exception.StackTrace);

                DisplayManager.PushNotification("Something went wrong with your twitter implementation.");
                navigateToTwitterHome();
            };

            // Recover from errors having to do with exceptions in dm users thread
            Interactor.getDmUsersNavigatable().OnExp = exception =>
            {
                Debug.Log(exception.Message.ToString());
                Crashlytics.RecordCustomException("Twitter Exception", "thrown exception", exception.StackTrace);

                DisplayManager.PushNotification("Something went wrong with your twitter implementation.");
                navigateToTwitterHome();
            };

            navigateToTwitterHome();
        }
        else         // Otherwise, we need to authenticate the user.
        {
            navigateToTwitterAuthPage();
        }
    }