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()); } }
/// <summary> /// Validates an application key signatures by calling accounts.exchangeUIDSignature and checking the response signature. /// </summary> public bool ValidateApplicationKeySignature(string userId, IGigyaModuleSettings settings, GSResponse originalResponse) { // this uses the Send method which validates the signature var response = ExchangeSignature(userId, settings, originalResponse.GetString(Constants.GigyaFields.UserIdSignature, null), originalResponse.GetString(Constants.GigyaFields.SignatureTimestamp, null), settings.ApplicationKey); return(ValidateExchangeSignatureResponse(response)); }
public static HttpCookie buildCookie(GSResponse res) { HttpCookie cookie = new HttpCookie(res.GetString("cookieName", string.Empty)); cookie.Domain = res.GetString("cookieDomain", string.Empty); cookie.Path = res.GetString("cookiePath", string.Empty); cookie.Value = res.GetString("cookieValue", string.Empty); //cookie.Expires = DateTime.MinValue; //cookie.HttpOnly = true; return cookie; }
public static void setCookie(GSResponse res, ControllerContext context) { HttpCookie cookie = new HttpCookie(res.GetString("cookieName", string.Empty)); //cookie.Domain = res.GetString("cookieDomain", string.Empty); //cookie.Path = res.GetString("cookiePath", string.Empty); cookie.Value = res.GetString("cookieValue", string.Empty); //cookie.Expires = DateTime.MinValue; cookie.Expires = DateTime.Now.AddDays(30); //cookie.HttpOnly = true; context.HttpContext.Response.Cookies.Add(cookie); }
public async Task <bool> Register(string password) { // Step 1 - Defining the request GSRequest initRequest = getGigyaRequest("accounts.initRegistration"); GSResponse initResponse = await Task <GSResponse> .Factory.FromAsync(initRequest.BeginSend, initRequest.EndSend, TaskCreationOptions.None); if (initResponse.GetErrorCode() != 0) { return(false); } string regToken = initResponse.GetString("regToken", null); GSRequest regRequest = getGigyaRequest("accounts.register"); // Step 2 - Adding parameters //regRequest.SetParam("username", Email); regRequest.SetParam("email", Email); // set the "uid" parameter to user's ID regRequest.SetParam("password", password); regRequest.SetParam("regToken", regToken); regRequest.SetParam("finalizeRegistration", true); // Step 3 - Sending the request GSResponse regresponse = await Task <GSResponse> .Factory.FromAsync(regRequest.BeginSend, regRequest.EndSend, TaskCreationOptions.None); // Step 4 - handling the request's response. if (regresponse.GetErrorCode() == 0) { // SUCCESS! response status = OK return(true); } else { // Error return(false); } }
private bool ValidateExchangeSignatureResponse(GSResponse response) { // if signature is invalid a null response is returned return(response != null && response.GetErrorCode() == 0 && !string.IsNullOrEmpty(response.GetString(Constants.GigyaFields.UserId, null))); }
/// <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); }
public bool ValidateSignature(string userId, IGigyaModuleSettings settings, GSResponse response, bool disableSignatureExchange = false) { return(SigUtils.ValidateUserSignature(userId, response.GetString(Constants.GigyaFields.SignatureTimestamp, null), settings.ApplicationSecret, response.GetString(Constants.GigyaFields.UserIdSignature, null))); }