protected ExpandoObject GetAccountInfo(object currentSiteId, IGigyaModuleSettings settings, GSResponse userInfoResponse, List <MappingField> mappingFields) { var userInfo = JsonConvert.DeserializeObject <ExpandoObject>(userInfoResponse.GetResponseText()); ThrowTestingExceptionIfRequired(settings, userInfo); var siteId = ConvertCurrentSiteId(currentSiteId); // fire getAccountInfo completed event var getAccountInfoCompletedArgs = new GetAccountInfoCompletedEventArgs { GigyaModel = userInfo, Settings = settings, Logger = _logger, MappingFields = mappingFields, CurrentSiteId = siteId }; GigyaEventHub.Instance.RaiseGetAccountInfoCompleted(this, getAccountInfoCompletedArgs); // fire merge getAccountInfo completed event var accountInfoMergeCompletedArgs = new AccountInfoMergeCompletedEventArgs { GigyaModel = getAccountInfoCompletedArgs.GigyaModel, Settings = settings, Logger = _logger, CurrentSiteId = siteId }; GigyaEventHub.Instance.RaiseAccountInfoMergeCompleted(this, accountInfoMergeCompletedArgs); return(accountInfoMergeCompletedArgs.GigyaModel); }
static void TestAsyncGSRequest() { string method = "socialize.getUserInfo"; // Should give response from server GSRequest request = new GSRequest(apiKey, secretKey, method, false); request.SetParam("uid", "3111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); request.SetParam("enabledProviders", "*,testnetwork,testnetwork2"); request.APIDomain = ""; GSResponse response = null; IAsyncResult iar = request.BeginSend((IAsyncResult innerIAsyncResult) => { response = request.EndSend(innerIAsyncResult); }, 123); iar.AsyncWaitHandle.WaitOne(); System.Console.WriteLine("Response: " + response.GetResponseText()); // Should fail before getting to server //request = new GSRequest(apiKey, secretKey+"123", method, false); //request.SetParam("uid", "di1"); //request.SetParam("enabledProviders", "*,testnetwork,testnetwork2"); //response = null; //iar = request.BeginSend((IAsyncResult innerIAsyncResult) => { // response = request.EndSend(innerIAsyncResult); //}, 123); //iar.AsyncWaitHandle.WaitOne(); }
private void HandleGSResponse(GSResponse res, string format) { lblVerifiedSig.Text = ""; if (!format.Equals("xml", StringComparison.InvariantCultureIgnoreCase)) { format = "txt"; } var filename = Path.Combine(Path.GetTempPath(), "1." + format); try { if (res.GetErrorCode() > 0) { lblVerifiedSig.ForeColor = Color.Red; lblVerifiedSig.Text = "Error !!!"; File.WriteAllText(filename, res.ToString()); } else { if (verifySignature) { verifyResponseSignature(res, format); } else { lblVerifiedSig.Text = "Data is ready"; } File.WriteAllText(filename, res.GetResponseText()); } webBrowser1.Navigate(filename); webBrowser1.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } btnSubmit.Text = "Submit"; btnSubmit.Enabled = true; }
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); } }
/// <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); }
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); }