Ejemplo n.º 1
0
        public string Generate(NetsuiteSignatureParamaters paramaters)
        {
            var newTimestamp = GenerateTimestamp();
            var newNonce     = GenerateNonce();

            return(GenerateWithNonceAndTimestamp(paramaters, newTimestamp, newNonce));
        }
Ejemplo n.º 2
0
        private string GenerateSignature(NetsuiteSignatureParamaters paramaters, int timestamp, string nonce)
        {
            var rightSide = string.Format(
                "deploy={0}&oauth_consumer_key={1}&oauth_nonce={2}&oauth_signature_method={3}&oauth_timestamp={4}&oauth_token={5}&oauth_version={6}&script={7}",
                paramaters.DeploymentId,
                paramaters.ConsumerKey,
                nonce,
                paramaters.SignatureMethod,
                timestamp,
                paramaters.TokenKey,
                "1.0",
                paramaters.ScriptId
                );

            var baseString = string.Format(
                "{0}&{1}&{2}",
                paramaters.HttpMethod,
                Uri.EscapeDataString(paramaters.NetsuiteUrl.ToLower()),
                Uri.EscapeDataString(rightSide)
                );

            var signature = Generate(paramaters.ConsumerSecret, paramaters.TokenSecret, baseString);

            return(Uri.EscapeDataString(signature));
        }
Ejemplo n.º 3
0
 private string CreateAuth(NetsuiteSignatureParamaters paramaters, string signature, int timestamp, string nonce)
 {
     return(string.Format(
                "OAuth realm=\"{0}\",oauth_consumer_key=\"{1}\",oauth_token=\"{2}\",oauth_signature_method=\"{3}\",oauth_timestamp=\"{4}\",oauth_nonce=\"{5}\",oauth_version=\"1.0\",oauth_signature=\"{6}\"",
                paramaters.NetsuiteId,
                paramaters.ConsumerKey,
                paramaters.TokenKey,
                paramaters.SignatureMethod,
                timestamp,
                nonce,
                signature
                ));
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var parameters = new NetsuiteSignatureParamaters
            {
                ConsumerKey    = string.Empty,
                ConsumerSecret = string.Empty,
                DeploymentId   = string.Empty,
                HttpMethod     = string.Empty,
                NetsuiteId     = string.Empty,
                NetsuiteUrl    = string.Empty,
                ScriptId       = string.Empty,
                TokenKey       = string.Empty,
                TokenSecret    = string.Empty
            };

            var generator = new NetSuiteSignatureGenerator();

            var signature = generator.Generate(parameters);

            Console.WriteLine(signature);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", signature);

                var result = client.GetAsync(string.Empty).Result;

                if (!result.IsSuccessStatusCode)
                {
                    var content = result.Content.ReadAsStringAsync().Result;

                    throw new Exception(content);
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 5
0
 public string GenerateWithNonceAndTimestamp(NetsuiteSignatureParamaters paramaters, int timestamp, string nonce)
 {
     return(CreateAuth(paramaters, GenerateSignature(paramaters, timestamp, nonce), timestamp, nonce));
 }