예제 #1
0
        public IEnumerable <IOAuthQueryParameter> GenerateApplicationParameters(
            IReadOnlyConsumerCredentials temporaryCredentials,
            IAuthenticationRequest authRequest = null,
            IEnumerable <IOAuthQueryParameter> additionalParameters = null)
        {
            var headers = GenerateConsumerParameters(temporaryCredentials).ToList();

            // Add Header for authenticated connection to a Twitter Application
            if (authRequest != null &&
                !string.IsNullOrEmpty(authRequest.AuthorizationKey) &&
                !string.IsNullOrEmpty(authRequest.AuthorizationSecret))
            {
                headers.Add(new OAuthQueryParameter("oauth_token", StringFormater.UrlEncode(authRequest.AuthorizationKey), true, true, false));
                headers.Add(new OAuthQueryParameter("oauth_token_secret", StringFormater.UrlEncode(authRequest.AuthorizationSecret), false, false, true));
            }
            else
            {
                headers.Add(new OAuthQueryParameter("oauth_token", "", false, false, true));
            }

            if (additionalParameters != null)
            {
                headers.AddRange(additionalParameters);
            }

            return(headers);
        }
예제 #2
0
        public static string GetBearerTokenAuthorizationHeader(IReadOnlyConsumerCredentials credentials)
        {
            var concatenatedCredentials = StringFormater.UrlEncode(credentials.ConsumerKey) + ":" + StringFormater.UrlEncode(credentials.ConsumerSecret);
            var credBytes         = Encoding.UTF8.GetBytes(concatenatedCredentials);
            var base64Credentials = Convert.ToBase64String(credBytes);

            return("Basic " + base64Credentials);
        }
        public static string CreateHash(IReadOnlyConsumerCredentials credentials)
        {
            if (credentials is IReadOnlyTwitterCredentials twitterCredentials)
            {
                return(CreateHash(twitterCredentials));
            }

            return($"{credentials.ConsumerKey} - {credentials.ConsumerSecret} - {credentials.BearerToken}");
        }
예제 #4
0
        public TwitterCredentials(IReadOnlyConsumerCredentials source)
        {
            if (source == null)
            {
                return;
            }

            ConsumerKey    = source.ConsumerKey;
            ConsumerSecret = source.ConsumerSecret;
            BearerToken    = source.BearerToken;
        }
예제 #5
0
        public static string CreateHash(IReadOnlyConsumerCredentials credentials)
        {
            var hash = $"{credentials.ConsumerKey} - {credentials.ConsumerSecret} - {credentials.BearerToken}";
            var twitterCredentials = credentials as IReadOnlyTwitterCredentials;

            if (twitterCredentials == null)
            {
                return(hash);
            }

            return($"{hash} - {twitterCredentials.AccessToken}  - {twitterCredentials.AccessTokenSecret}");
        }
예제 #6
0
        private static IEnumerable <IOAuthQueryParameter> GenerateConsumerParameters(IReadOnlyConsumerCredentials consumerCredentials)
        {
            var consumerHeaders = new List <IOAuthQueryParameter>();

            // Add Header for every connection to a Twitter Application
            if (consumerCredentials != null &&
                !string.IsNullOrEmpty(consumerCredentials.ConsumerKey) &&
                !string.IsNullOrEmpty(consumerCredentials.ConsumerSecret))
            {
                consumerHeaders.Add(new OAuthQueryParameter("oauth_consumer_key", StringFormater.UrlEncode(consumerCredentials.ConsumerKey), true, true, false));
                consumerHeaders.Add(new OAuthQueryParameter("oauth_consumer_secret", StringFormater.UrlEncode(consumerCredentials.ConsumerSecret), false, false, true));
            }

            return(consumerHeaders);
        }
 public ConsumerOnlyCredentials(IReadOnlyConsumerCredentials creds)
 {
     ConsumerKey    = creds?.ConsumerKey;
     ConsumerSecret = creds?.ConsumerSecret;
     BearerToken    = creds?.BearerToken;
 }
예제 #8
0
 public ReadOnlyTwitterCredentials(IReadOnlyConsumerCredentials source) : base(source)
 {
 }
예제 #9
0
 public ReadOnlyTwitterCredentials(IReadOnlyConsumerCredentials consumerCredentials, string accessToken, string accessTokenSecret) : base(consumerCredentials)
 {
     AccessToken       = accessToken;
     AccessTokenSecret = accessTokenSecret;
 }
예제 #10
0
 public TwitterInvalidCredentialsException(IReadOnlyConsumerCredentials credentials)
     : base("The consumer key and consumer secret must be defined!")
 {
     Credentials = credentials;
 }
 public ReadOnlyConsumerCredentials(IReadOnlyConsumerCredentials source)
 {
     ConsumerKey    = source?.ConsumerKey;
     ConsumerSecret = source?.ConsumerSecret;
     BearerToken    = source?.BearerToken;
 }
예제 #12
0
 public TwitterCredentials(IReadOnlyConsumerCredentials credentials) : base(credentials)
 {
 }