Example #1
0
        public AuthResponse AuthenticateMe(IAuthenticateSettings authenticateSettings)
        {
            AuthResponse twitAuthResponse = null;
            // Do the Authenticate
            var authHeaderFormat = "Basic {0}";

            var authHeader = string.Format(authHeaderFormat,
                                           Convert.ToBase64String(
                                               Encoding.UTF8.GetBytes(Uri.EscapeDataString(authenticateSettings.OAuthConsumerKey) + ":" +

                                                                      Uri.EscapeDataString((authenticateSettings.OAuthConsumerSecret)))

                                               ));
            var            postBody    = "grant_type=client_credentials";
            HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(authenticateSettings.OAuthUrl);

            authRequest.Headers.Add("Authorization", authHeader);
            authRequest.Method                 = "POST";
            authRequest.ContentType            = "application/x-www-form-urlencoded;charset=UTF-8";
            authRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            authRequest.UserAgent              = "gamb.com";
            using (Stream stream = authRequest.GetRequestStream())
            {
                byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
                stream.Write(content, 0, content.Length);
            }
            authRequest.Headers.Add("Accept-Encoding", "gzip");
            WebResponse authResponse = authRequest.GetResponse();

            // deserialize into an object
            using (authResponse)
            {
                using (var reader = new StreamReader(authResponse.GetResponseStream()))
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    var objectText          = reader.ReadToEnd();
                    twitAuthResponse = JsonConvert.DeserializeObject <AuthResponse>(objectText);
                }
            }

            return(twitAuthResponse);
        }
Example #2
0
        public AuthResponse AuthenticateMe(IAuthenticateSettings authenticateSettings)
        {
            AuthResponse twitAuthResponse = null;
            // Do the Authenticate
            var authHeaderFormat = "Basic {0}";

            var authHeader = string.Format(authHeaderFormat,
                                           Convert.ToBase64String(
                                               Encoding.UTF8.GetBytes(Uri.EscapeDataString(authenticateSettings.OAuthConsumerKey) + ":" +

                                                                      Uri.EscapeDataString((authenticateSettings.OAuthConsumerSecret)))

                                               ));
            var postBody = "grant_type=client_credentials";
            HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(authenticateSettings.OAuthUrl);

            authRequest.Headers.Add("Authorization", authHeader);
            authRequest.Method = "POST";
            authRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
            authRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            using (Stream stream = authRequest.GetRequestStream())
            {
                byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
                stream.Write(content, 0, content.Length);
            }
            authRequest.Headers.Add("Accept-Encoding", "gzip");
            WebResponse authResponse = authRequest.GetResponse();
            // deserialize into an object
            using (authResponse)
            {
                using (var reader = new StreamReader(authResponse.GetResponseStream()))
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    var objectText = reader.ReadToEnd();
                    twitAuthResponse = JsonConvert.DeserializeObject<AuthResponse>(objectText);
                }
            }

            return twitAuthResponse;
            //
        }
 /// <summary>
 /// This allows the authentications, timeline and search settings to be passed in
 /// </summary>
 /// <param name="authenticateSettings"></param>
 /// <param name="timeLineSettings"></param>
 /// <param name="searchSettings"></param>
 public OAuthTwitterWrapper(IAuthenticateSettings authenticateSettings, ITimeLineSettings timeLineSettings, ISearchSettings searchSettings)
 {
     AuthenticateSettings = authenticateSettings;
     TimeLineSettings     = timeLineSettings;
     SearchSettings       = searchSettings;
 }
 /// <summary>
 /// This allows the authentications settings to be passed in
 /// </summary>
 /// <param name="authenticateSettings"></param>
 public OAuthTwitterWrapper(IAuthenticateSettings authenticateSettings)
 {
     AuthenticateSettings = authenticateSettings;
 }
 /// <summary>
 /// This allows the authentications, timeline and search settings to be passed in
 /// </summary>
 /// <param name="authenticateSettings"></param>
 /// <param name="timeLineSettings"></param>
 /// <param name="searchSettings"></param>
 public OAuthTwitterWrapper(IAuthenticateSettings authenticateSettings, ITimeLineSettings timeLineSettings, ISearchSettings searchSettings)
 {
     AuthenticateSettings = authenticateSettings;
     TimeLineSettings = timeLineSettings;
     SearchSettings = searchSettings;
 }
 /// <summary>
 /// This allows the authentications settings to be passed in
 /// </summary>
 /// <param name="authenticateSettings"></param>
 public OAuthTwitterWrapper(IAuthenticateSettings authenticateSettings)
 {
     AuthenticateSettings = authenticateSettings;
 }