Exemplo n.º 1
0
        private void AddAuthParameters(ICollection <WebParameter> parameters, string?timestamp, string?nonce)
        {
            if (string.IsNullOrWhiteSpace(this.ConsumerKey))
            {
                throw new NullReferenceException($"{nameof(this.ConsumerKey)} must not be null, empty or whitespace");
            }

            if (string.IsNullOrWhiteSpace(timestamp))
            {
                throw new NullReferenceException($"parameter {nameof(timestamp)} must not be null, empty or whitespace");
            }

            if (string.IsNullOrWhiteSpace(nonce))
            {
                throw new NullReferenceException($"parameter {nameof(nonce)} must not be null, empty or whitespace");
            }

            var authParameters = new WebParameterCollection
            {
                new WebParameter("oauth_consumer_key", this.ConsumerKey),
                new WebParameter("oauth_nonce", nonce),
                new WebParameter("oauth_signature_method", ToRequestValue(this.SignatureMethod)),
                new WebParameter("oauth_timestamp", timestamp),
                new WebParameter("oauth_version", this.Version ?? "1.0")
            };

            if (!string.IsNullOrWhiteSpace(this.Token))
            {
                authParameters.Add(new WebParameter("oauth_token", this.Token));
            }

            if (!string.IsNullOrWhiteSpace(this.CallbackUrl))
            {
                authParameters.Add(new WebParameter("oauth_callback", this.CallbackUrl));
            }

            if (!string.IsNullOrWhiteSpace(this.Verifier))
            {
                authParameters.Add(new WebParameter("oauth_verifier", this.Verifier));
            }

            if (!string.IsNullOrWhiteSpace(this.SessionHandle))
            {
                authParameters.Add(new WebParameter("oauth_session_handle", this.SessionHandle));
            }

            foreach (var authParameter in authParameters)
            {
                parameters.Add(authParameter);
            }
        }
Exemplo n.º 2
0
        private string GetSignatureAuthorizationQuery(WebParameterCollection parameters)
        {
            var signature = GetNewSignature(parameters);

            parameters.Add("oauth_signature", signature);

            return(WriteAuthorizationQuery(parameters));
        }
Exemplo n.º 3
0
        private string GetClientSignatureAuthorizationHeader(WebParameterCollection parameters)
        {
            var signature = GetNewSignatureXAuth(parameters);

            parameters.Add("oauth_signature", signature);

            return(WriteAuthorizationHeader(parameters));
        }