private static BaseAuthenticationInfo LocateLinkedinResponse() { var authorization = new WebOAuthAuthorization(LinkedinTokenManager, null); string accessToken; try { accessToken = authorization.CompleteAuthorize(); } catch (Exception ex) { return null; } if (accessToken != null) { authorization = new WebOAuthAuthorization(LinkedinTokenManager, accessToken); LinkedInService service = new LinkedInService(authorization); var profile = service.GetCurrentUser(ProfileType.Public); var info = new LinkedinAuthenticationInfo(); info.FirstName = profile.FirstName; info.LastName = profile.LastName; info.Identifier = profile.Id; info.UserName = profile.Name; info.Provider = providerModule.GetProvider("LinkedIn"); return info; } else { return null; } }
private LinkedInService GetLinkedInService() { var authorization = new WebOAuthAuthorization(_tokenManager, _accessToken); return new LinkedInService(authorization); }
public ActionResult LogOnUsingOpenId(string site) { var locatedUser = ProvidersLocator.LocateService(); if (locatedUser != null) { var id = locatedUser.Identifier; if (!String.IsNullOrEmpty(id)) { Session.User = new User(); Session.User.ProviderUserId = id; Session.User.ProviderId = (int)locatedUser.Provider.Id; var identifier = userModule.GetUserByProviderUserId(id); if (identifier != null) { Session.User.Id = identifier.Id; Session.User = userModule.GetUser(identifier.UserName); ViewData["UserName"] = Session.User.UserName; FormsService.SignIn(identifier.UserName, false); Session.SessionEndTime = DateTime.Now; return Redirect(Url.Home()); } else { ViewData["ProviderId"] = id; return Redirect(Url.Register(), true); } } } switch (site) { case "twitter": var client = new TwitterClient(ProvidersLocator.TwitterTokenManager); client.StartAuthentication(Request.Url); break; case "google": TransferToOpenIdProvider(OpenIdProviderEndPoints.Google.EndPoint); break; case "vkontakte": TransferToOpenIdProvider(OpenIdProviderEndPoints.VKontakte.EndPoint); break; case "linkedin": var authorization = new WebOAuthAuthorization(ProvidersLocator.LinkedinTokenManager, null); var callback = Request.Url; authorization.BeginAuthorize(callback); break; case "myspace": TransferToOpenIdProvider(OpenIdProviderEndPoints.MySpace.EndPoint); break; } ViewData.Model = new AccountModel(new LogOnModel()); return View("LogOn"); }
public ActionResult AccountBinding(BindingModel model, string site) { switch (site) { case "twitter": var client = new TwitterClient(ProvidersLocator.TwitterTokenManager); client.StartAuthentication(Request.Url); break; case "google": TransferToOpenIdProvider(OpenIdProviderEndPoints.Google.EndPoint); break; case "vkontakte": TransferToOpenIdProvider(OpenIdProviderEndPoints.VKontakte.EndPoint); break; case "linkedin": var authorization = new WebOAuthAuthorization(ProvidersLocator.LinkedinTokenManager, null); var callback = Request.Url; authorization.BeginAuthorize(callback); break; case "myspace": TransferToOpenIdProvider(OpenIdProviderEndPoints.MySpace.EndPoint); break; default: int curProviderId; string curProviderUserId; userBind = userModule.GetUserByProviderUserId(model.AccountBinding.ProviderUserId); if (userBind != null) userModule.CleanProvider(model.AccountBinding.ProviderUserId); curProviderId = model.AccountBinding.ProviderId; curProviderUserId = model.AccountBinding.ProviderUserId; if (userModule.AddProvider(curProviderId, curProviderUserId, Session.User.Id)) { HttpCookie providerCookie = new HttpCookie("SkynerCookie"); Session.User.ProviderId = curProviderId; Session.User.ProviderUserId = curProviderUserId; providerCookie.Value = providerModule.GetProvider(Session.User.ProviderId).Name; Response.Cookies.Add(providerCookie); ViewData["UserName"] = Session.User.UserName; ViewData.Model = null; return RedirectToAction("AccountBindingSuccess", "Account"); } break; } model.Session = Session; return View(); }