Ejemplo n.º 1
0
        static void TestGetUserInfo(string[] args)
        {
            // Step 1 - Defining the request
            string    method  = "socialize.getUserInfo";
            GSRequest request = new GSRequest(apiKey, secretKey, method, true);

            // Step 2 - Adding parameters
            request.SetParam("uid", "di1");                   // set the "uid" parameter to user's ID
            request.SetParam("enabledProviders", "*,testnetwork,testnetwork2");
            request.SetParam("status", "I feel great 22222"); // set the "status" parameter to "I feel great"

            // Step 3 - Sending the request
            GSResponse response = request.Send();

            bool validate = SigUtils.ValidateUserSignature(
                response.GetString("UID", ""),
                response.GetString("signatureTimestamp", ""), secretKey,
                response.GetString("UIDSignature", ""));

            // Step 4 - handling the request's response.
            if (response.GetErrorCode() == 0)
            {    // SUCCESS! response status = OK
                Console.WriteLine("Success in setStatus operation.");
            }
            else
            {  // Error
                Console.WriteLine("Got error on setStatus: {0}", response.GetErrorMessage());
            }
        }
        private GSResponse LogError(GSResponse response, string method, Exception e)
        {
            dynamic gigyaModel = response != null?JsonConvert.DeserializeObject <ExpandoObject>(response.GetResponseText()) : new ExpandoObject();

            var gigyaError = response != null?response.GetErrorMessage() : string.Empty;

            var gigyaErrorDetail = DynamicUtils.GetValue <string>(gigyaModel, "errorDetails");
            var gigyaCallId      = DynamicUtils.GetValue <string>(gigyaModel, "callId");

            _logger.Error(string.Format("API call: {0}. CallId: {1}. Error: {2}. Error Details: {3}.", method, gigyaCallId, gigyaError, gigyaErrorDetail), e);
            return(response);
        }
Ejemplo n.º 3
0
        public static void LogResponseIfRequired(Logger logger, IGigyaModuleSettings settings, string apiMethod, GSResponse response)
        {
            if (settings.DebugMode)
            {
                dynamic gigyaModel = response != null?JsonConvert.DeserializeObject <ExpandoObject>(response.GetResponseText()) : new ExpandoObject();

                var gigyaError = response != null?response.GetErrorMessage() : string.Empty;

                var gigyaErrorDetail = DynamicUtils.GetValue <string>(gigyaModel, "errorDetails");

                var callId = DynamicUtils.GetValue <string>(gigyaModel, "callId");
                logger.DebugFormat("API call: {0}. CallId: {1}. Error: {2}. Error Details: {3}.", apiMethod, callId, gigyaError, gigyaErrorDetail);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a request to the Gigya API.
        /// </summary>
        /// <param name="request">Request object.</param>
        /// <param name="apiMethod">The Gigya method to call.</param>
        /// <param name="settings">The Gigya module settings.</param>
        /// <param name="validateSignature">If set to true, the signature will be validated.</param>
        /// <returns></returns>
        private GSResponse Send(GSRequest request, string apiMethod, IGigyaModuleSettings settings, bool validateSignature)
        {
            if (apiMethod == "accounts.getAccountInfo")
            {
                var environment = new
                {
                    cms_name      = _settingsHelper.CmsName,
                    cms_version   = _settingsHelper.CmsVersion,
                    gigya_version = _settingsHelper.ModuleVersion
                };

                request.SetParam("environment", JsonConvert.SerializeObject(environment));
            }

            if (!string.IsNullOrEmpty(settings.DataCenter))
            {
                request.APIDomain = settings.DataCenter;
            }

            LogRequestIfRequired(settings, apiMethod);

            GSResponse response = null;

            try
            {
                response = request.Send();
            }
            catch (Exception e)
            {
                dynamic gigyaModel = response != null?JsonConvert.DeserializeObject <ExpandoObject>(response.GetResponseText()) : new ExpandoObject();

                var gigyaError = response != null?response.GetErrorMessage() : string.Empty;

                var gigyaErrorDetail = DynamicUtils.GetValue <string>(gigyaModel, "errorDetails");
                var gigyaCallId      = DynamicUtils.GetValue <string>(gigyaModel, "callId");

                _logger.Error(string.Format("API call: {0}. CallId: {1}. Error: {2}. Error Details: {3}.", apiMethod, gigyaCallId, gigyaError, gigyaErrorDetail), e);
                return(response);
            }

            LogResponseIfRequired(settings, apiMethod, response);

            if (response.GetErrorCode() != 0)
            {
                return(response);
            }

            var userId = response.GetString(Constants.GigyaFields.UserId, null);

            if (string.IsNullOrEmpty(userId))
            {
                return(response);
            }

            // no need to validate server calls unless explicitly required e.g. for signature exchange
            if (validateSignature && !ValidateSignature(userId, settings, response))
            {
                if (settings.DebugMode)
                {
                    dynamic gigyaModel = response != null?JsonConvert.DeserializeObject <ExpandoObject>(response.GetResponseText()) : new ExpandoObject();

                    var gigyaCallId = DynamicUtils.GetValue <string>(gigyaModel, "callId");

                    _logger.DebugFormat("Invalid user signature for login request. API call: {0}. CallId: {1}.", apiMethod, gigyaCallId);
                }
                return(null);
            }

            return(response);
        }