コード例 #1
0
        private static TokenPassport CreateTokenPassport()
        {
            Stopwatch sw = new Stopwatch();

            string account        = "606500_SB1";
            string consumerKey    = "e0a74c549bfa07f950eff91b41292ab3bc4cf9e62718cea85fc5fe87950272e3";
            string consumerSecret = "cfeb3ac9ac84ad933c08e1de083660204cbf3844231d75341603f1d532f1d4eb";
            string tokenId        = "9bcab909033a99936c7e569b6432be961f432c4336131f88779883f4b9d743c2";
            string tokenSecret    = "f027714435a5b30aa7af437a5a93b129b2c71c41db4a1d5dd6202abda00a3016";

            string nonce     = ComputeNonce();
            long   timestamp = ComputeTimestamp();

            sw.Start();
            TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);

            TokenPassport tokenPassport = new TokenPassport();

            tokenPassport.account     = account;
            tokenPassport.consumerKey = consumerKey;
            tokenPassport.token       = tokenId;
            tokenPassport.nonce       = nonce;
            tokenPassport.timestamp   = timestamp;
            tokenPassport.signature   = signature;
            sw.Stop();

            //_auditLog.AddLogDetails(AuditLogType.Information, $"{DateTime.UtcNow} Timestamp: {timestamp}, Token: {tokenId}, signature generation, ms: {sw.ElapsedMilliseconds}");

            return(tokenPassport);
        }
コード例 #2
0
        /// <summary>
        /// This generates the TokenPassport object used by the integration client for authenticating
        /// an account without using username and password combination
        ///
        /// </summary>
        /// <param name="account">ID of the NetSuite account you intend to connect to.</param>
        /// <param name="consumerKey">Generated by creating an integration record.</param>
        /// <param name="consumerSecret">Generated by creating an integration record.</param>
        /// <param name="tokenId">Generated when a token is created.</param>
        /// <param name="tokenSecret">Generated when a token is created.</param>
        /// <returns>Generated TokenPassport object</returns>
        public static TokenPassport generateTokenPassport(string account, string consumerKey, string consumerSecret, string tokenId, string tokenSecret)
        {
            generateNonce();
            generateTimestamp();

            TokenPassport tokenPassport = new TokenPassport
            {
                account     = account,
                consumerKey = consumerKey,
                token       = tokenId,
                nonce       = _nonce,
                timestamp   = _timestamp,
                signature   = getPassportSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret)
            };

            return(tokenPassport);
        }
コード例 #3
0
        public TokenPassport CreateTokenPassport()
        {
            string account        = ConfigurationManager.AppSettings["login.acct"];
            string consumerKey    = ConfigurationManager.AppSettings["login.tbaConsumerKey"];
            string consumerSecret = ConfigurationManager.AppSettings["login.tbaConsumerSecret"];
            string tokenId        = ConfigurationManager.AppSettings["login.tbaTokenId"];
            string tokenSecret    = ConfigurationManager.AppSettings["login.tbaTokenSecret"];

            string nonce     = ComputeNonce();
            long   timestamp = ComputeTimestamp();
            TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);

            TokenPassport tokenPassport = new TokenPassport();

            tokenPassport.account     = account;
            tokenPassport.consumerKey = consumerKey;
            tokenPassport.token       = tokenId;
            tokenPassport.nonce       = nonce;
            tokenPassport.timestamp   = timestamp;
            tokenPassport.signature   = signature;
            return(tokenPassport);
        }
コード例 #4
0
        public static NetSuiteService GetNetSuiteService()
        {
            if (passport == null)
            {
                passport             = new TokenPassport();
                passport.account     = ConfigurationManager.AppSettings["AccountID"];
                passport.consumerKey = ConfigurationManager.AppSettings["ConsumerKey"];
                passport.token       = ConfigurationManager.AppSettings["TokenId"];
                passport.nonce       = GenerateNonce(10);
                passport.timestamp   = (Int64)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                passport.signature   = GenerateSignature(passport.nonce, passport.timestamp);
            }

            if (service == null)
            {
                service = new NetSuiteService();
                service.tokenPassport = passport;
                service.Url           = ConfigurationManager.AppSettings["URL"];
            }

            return(service);
        }
コード例 #5
0
        public TokenPassport GetTokenPassport()
        {
            if (_tokenPassport == null)
            {
                lock (_tokenLock)
                {
                    if (_tokenPassport == null)
                    {
                        string env(string varName)
                        {
                            string value = Environment.GetEnvironmentVariable(varName);

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                return(value);
                            }
                            else
                            {
                                throw new InvalidOperationException(varName + " environment variable was not set.");
                            }
                        }

                        string consumerSecret = env(this.consumerSecretVariable);
                        string consumerKey    = env(this.consumerKeyVariable);

                        var passportBuilder = new DefaultTokenPassportBuilder(consumerKey, consumerSecret);

                        string token       = env(this.tokenVarible);
                        string tokenSecret = env(this.tokenSecretVariable);
                        string account     = env(this.accountVariable);

                        _tokenPassport = passportBuilder.Build(account, token, tokenSecret);
                    }
                }
            }
            return(_tokenPassport);
        }