// GET: Linkedin/Auth public ActionResult Auth(string code, string state) { try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; var client = new RestClient("https://www.linkedin.com/oauth/v2/accessToken"); var request = new RestRequest(Method.POST); request.AddParameter("grant_type", "authorization_code"); request.AddParameter("code", code); request.AddParameter("redirect_uri", System.Configuration.ConfigurationManager.AppSettings["LIAuthRedirectUri"].ToString()); request.AddParameter("client_id", System.Configuration.ConfigurationManager.AppSettings["LIAuthApiClientId"]); request.AddParameter("client_secret", System.Configuration.ConfigurationManager.AppSettings["LIAuthClientSecret"]); IRestResponse response = client.Execute(request); JsonDeserializer deserializer = new JsonDeserializer(); var content = deserializer.Deserialize <BunnyMerge.Helpers.AccessTokenHelper>(response); var tuple = connectLinkedin(content.access_token); var profile = tuple.Item1; response = tuple.Item2; var linkedInChecked = false; if (response.StatusCode == System.Net.HttpStatusCode.OK) { Session["LIUserName"] = profile.firstName; Session["LIUserId"] = profile.id; Session["access_token"] = content.access_token; linkedInChecked = true; } var torreBioChecked = false; var torreModel = new Models.TorreProfile(); if (Session["UserId"] != null && Session["UserId"] != string.Empty) { var torreController = new TorreBioController(); var userId = Session["UserId"].ToString(); var userName = Session["UserName"].ToString(); torreModel = torreController.connectTorre(userName).Item1; torreBioChecked = true; } if (torreBioChecked && linkedInChecked) { Session["MergeLITorre"] = new Models.MergeLITorre() { LIProfile = profile, TorreProfile = torreModel } } ; return(RedirectToAction("Index", "Home")); } catch (Exception ex) { throw ex; } }
public ActionResult SignInT(string username) { var tuple = connectTorre(username); var content = tuple.Item1; var response = tuple.Item2; var torreBioChecked = false; if (response.StatusCode == System.Net.HttpStatusCode.OK) { Session["userName"] = content.person.publicId; Session["userId"] = content.person.id; torreBioChecked = true; } var linkedInModel = new Models.BasicProfile(); var linkedInChecked = false; if (Session["LIUserId"] != null && Session["LIUserId"] != string.Empty) { var linkedInController = new LinkedInController(); var userId = Session["UserId"].ToString(); var userName = Session["UserName"].ToString(); var access_token = Session["access_token"].ToString(); linkedInModel = linkedInController.connectLinkedin(access_token).Item1; linkedInChecked = true; } if (torreBioChecked && linkedInChecked) { Session["MergeLITorre"] = new Models.MergeLITorre() { LIProfile = linkedInModel, TorreProfile = content } } ; return(RedirectToAction("Index", "Home")); }