示例#1
0
        /// <summary>
        /// Method used to remove the tokens object from the database.  This is called when a refresh fails; the refresh token is invalid and therefor the data is invalid.
        /// The admin must reconfigure the SRM Oauth process if/when this method is called.
        /// </summary>
        /// <param name="globalContext"></param>
        /// <returns></returns>
        public bool RemoveOauthTokens(IGlobalContext globalContext)
        {
            ConfigurationSetting.logWrap.NoticeLog(logMessage: Properties.Resources.RemovingTokenNoticeLabel, logNote: Properties.Resources.RemovingTokenNoticeLabel);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var tokenQuery = String.Format("SELECT ID FROM Accelerator.OAuthTokens WHERE Account = {0} LIMIT 1", globalContext.AccountId);
            var results    = ConfigurationSetting.rnSrv.queryData(tokenQuery);

            if (results.Length > 0)
            {
                var id     = results[0];
                var token  = GenericObjectFactory.CreateGenericObject("OAuthTokens", "Accelerator", Convert.ToInt32(id));
                var objArr = new RightNowServiceReference.RNObject[] { token };
                ConfigurationSetting.rnSrv.destroyObjects(objArr);

                if (TokensRemovedFromServer != null)
                {
                    TokensRemovedFromServer(this, EventArgs.Empty);
                }
            }
            stopwatch.Stop();
            ConfigurationSetting.logWrap.DebugLog(logMessage: Properties.Resources.RemovedTokenLabel, logNote: Properties.Resources.RemovedTokenLabel, timeElapsed: (int)stopwatch.ElapsedMilliseconds);

            return(false);
        }
示例#2
0
        /// <summary>
        /// Update the agent account oauth custom field timestamp with a new value 15 mins in the future.
        /// Only add-ins that leverage this library will update the timestamp, so scripts that validate against the timestamp will only succeed
        /// if this add-in is active and updating this field every 15 mins.
        /// </summary>
        /// <param name="globalContext"></param>
        private void SetValidRequestTime(IGlobalContext globalContext)
        {
            var now       = System.DateTime.UtcNow;
            var validTime = now.AddSeconds(900);

            //Update the agent field through the SOAP API
            var rntService = new RightNowService(globalContext);
            var agent      = new RightNowServiceReference.Account()
            {
                ID = new RightNowServiceReference.ID()
                {
                    id          = globalContext.AccountId,
                    idSpecified = true
                }
            };

            //Get the current process so that we can use process ID as one of the validation mechanisms that we use when posting a request
            //To the Oauth controller.
            var process = System.Diagnostics.Process.GetCurrentProcess();

            //Setup the custom fields to be saved to the agent record via the SOAP API
            var processIdField = GenericObjectFactory.CreateGenericIntegerField(@"OAuthProcessId", process.Id);
            var timestampField = GenericObjectFactory.CreateGenericDateTimeField(@"OAuthRequestValidUntil", validTime);
            var accountCustomFieldsAccelerator = GenericObjectFactory.CreateGenericObject(@"AccountCustomFieldsAccelerator", null);

            accountCustomFieldsAccelerator.GenericFields = new RightNowServiceReference.GenericField[] { timestampField, processIdField };
            var cField = GenericObjectFactory.CreateGenericObjectField("Accelerator", accountCustomFieldsAccelerator);

            agent.CustomFields = GenericObjectFactory.CreateGenericObject("AgentCustomFields", null);
            agent.CustomFields.GenericFields = new RightNowServiceReference.GenericField[] { cField };

            rntService.updateObject(new RightNowServiceReference.RNObject[] { agent });

            //Update our stored config object with the new timestamp
            OAuthRequestTimeout = ConvertToTimestamp(validTime);
        }
示例#3
0
        /// <summary>
        /// Sets the RefreshTokenFailure flag to true to indicate that the access token failed and the controller should try to
        /// request a new token on the next token request.
        /// </summary>
        /// <param name="globalContext"></param>
        /// <returns></returns>
        public bool SetCurrentAccessTokenInvalid(IGlobalContext globalContext)
        {
            ConfigurationSetting.logWrap.NoticeLog(logMessage: Properties.Resources.RemovingTokenNoticeLabel, logNote: Properties.Resources.RemovingTokenNoticeLabel);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var tokenQuery = String.Format("SELECT ID FROM Accelerator.OAuthTokens WHERE Account = {0} LIMIT 1", globalContext.AccountId);
            var results    = ConfigurationSetting.rnSrv.queryData(tokenQuery);

            if (results.Length > 0)
            {
                var id    = results[0];
                var token = GenericObjectFactory.CreateGenericObject("OAuthTokens", "Accelerator", Convert.ToInt32(id));
                token.GenericFields    = new RightNowServiceReference.GenericField[1];
                token.GenericFields[0] = GenericObjectFactory.CreateGenericBoolField("RefreshTokenFailure", true);

                var objArr = new RightNowServiceReference.RNObject[] { token };
                ConfigurationSetting.rnSrv.updateObject(objArr);
            }
            stopwatch.Stop();
            ConfigurationSetting.logWrap.DebugLog(logMessage: Properties.Resources.RemovedTokenLabel, logNote: Properties.Resources.RemovedTokenLabel, timeElapsed: (int)stopwatch.ElapsedMilliseconds);

            return(false);
        }