예제 #1
0
        /// <summary>
        /// Set the username and password for the client to obtain a vine sessionId.
        /// If this is called after the client has authenticated, it will reset authentication
        /// </summary>
        /// <param name="username">username to authenticate with</param>
        /// <param name="password">password for the user</param>
        public void SetCredentials(string username, string password)
        {
            _username = username;
            _password = password;

            _authenticatedUser = null;
        }
예제 #2
0
        private async Task <RestClient> GetClient(bool requireAuth = true)
        {
            var client = new RestClient
            {
                JsonSerializerSettings = GetSettings(),
                BaseUrl = VineEndpoints.BaseUrl
            };

            client.AddHeader("accept-language", "en, sv, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8");

            if (requireAuth && (string.IsNullOrWhiteSpace(_username) || string.IsNullOrWhiteSpace(_password)))
            {
                throw new VineSharpConfigurationException();
            }

            if (!requireAuth)
            {
                return(client);
            }

            // authenticate and add headers
            if (_authenticatedUser == null)
            {
                // Authenticate sets the _authenticatedUser property
                var authResult = await Authenticate();

                // set the current authenticated user
                _authenticatedUser = authResult.Data;
            }

            client.AddHeader("vine-session-id", _authenticatedUser.Key);

            return(client);
        }