From d2041b547a24e93a6a08ab2f999eb1730d39ea93 Mon Sep 17 00:00:00 2001 From: Anyelo Date: Thu, 7 Apr 2016 23:24:18 -0400 Subject: [PATCH 1/2] LinkedIn login. - Added linkedin login. - Fixed error on profile screen loading job opportunities by user because of null JobOpportunityLikes. --- .../UserProfileSocialService.cs | 13 ++++++++++++ .../UserProfileRepository.cs | 4 +++- EmpleoDotNet/App_Start/Startup.Auth.cs | 20 +++++++++++++------ EmpleoDotNet/Base_Auth.config | 2 ++ EmpleoDotNet/EmpleoDotNet.csproj | 4 ++++ .../Account/_ExternalLoginsListPartial.cshtml | 10 ++++++++-- EmpleoDotNet/packages.config | 1 + 7 files changed, 45 insertions(+), 9 deletions(-) diff --git a/EmpleoDotNet.AppServices/UserProfileSocialService.cs b/EmpleoDotNet.AppServices/UserProfileSocialService.cs index 263936a3..170a4640 100644 --- a/EmpleoDotNet.AppServices/UserProfileSocialService.cs +++ b/EmpleoDotNet.AppServices/UserProfileSocialService.cs @@ -21,11 +21,24 @@ public UserProfile GetFromSocialProvider(string socialProvider, ClaimsIdentity i return GetFromGoogle(identity); case "Microsoft": return GetFromMicrosoft(identity); + case "LinkedIn": + return GetFromLinkedIn(identity); default: return new UserProfile(); } } + private UserProfile GetFromLinkedIn(ClaimsIdentity identity) + { + var email = identity.FindFirst(x => x.Type.Contains("emailaddress")).Value; + var name = identity.Name; + return new UserProfile + { + Email = email, + Name = name + }; + } + private UserProfile GetFromMicrosoft(ClaimsIdentity identity) { var email = identity.FindFirst(x => x.Type.Contains("emailaddress")).Value; diff --git a/EmpleoDotNet.Repository/UserProfileRepository.cs b/EmpleoDotNet.Repository/UserProfileRepository.cs index ecabac55..973cc6ab 100644 --- a/EmpleoDotNet.Repository/UserProfileRepository.cs +++ b/EmpleoDotNet.Repository/UserProfileRepository.cs @@ -18,7 +18,9 @@ public UserProfileRepository(EmpleadoContext context) : base(context) public UserProfile GetByUserId(string userId) { - return DbSet.Where(x => x.UserId == userId).Include(x=>x.JobOpportunities).FirstOrDefault(); + return DbSet.Where(x => x.UserId == userId) + .Include(x => x.JobOpportunities.Select(j => j.JobOpportunityLikes)) + .FirstOrDefault(); } } } diff --git a/EmpleoDotNet/App_Start/Startup.Auth.cs b/EmpleoDotNet/App_Start/Startup.Auth.cs index f45a14b1..d82f8ef4 100644 --- a/EmpleoDotNet/App_Start/Startup.Auth.cs +++ b/EmpleoDotNet/App_Start/Startup.Auth.cs @@ -9,6 +9,7 @@ using Microsoft.Owin.Security.Google; using Microsoft.Owin.Security.MicrosoftAccount; using Owin; +using Owin.Security.Providers.LinkedIn; using Tweetinvi; namespace EmpleoDotNet @@ -35,17 +36,17 @@ public void ConfigureAuth(IAppBuilder app) msAuthOptions.ClientSecret = ConfigurationManager.AppSettings["msClientSecret"]; app.UseMicrosoftAccountAuthentication(msAuthOptions); -// app.UseTwitterAuthentication( -// consumerKey: ConfigurationManager.AppSettings["consumerKey"], -// consumerSecret: ConfigurationManager.AppSettings["consumerSecret"] -// ); + // app.UseTwitterAuthentication( + // consumerKey: ConfigurationManager.AppSettings["consumerKey"], + // consumerSecret: ConfigurationManager.AppSettings["consumerSecret"] + // ); var fbAuthOptions = new FacebookAuthenticationOptions { AppId = ConfigurationManager.AppSettings["fbAppId"], AppSecret = ConfigurationManager.AppSettings["fbAppSecret"] }; - + fbAuthOptions.Scope.Add("email"); fbAuthOptions.Scope.Add("public_profile"); fbAuthOptions.Scope.Add("user_friends"); @@ -53,15 +54,22 @@ public void ConfigureAuth(IAppBuilder app) { OnAuthenticated = context => { - context.Identity.AddClaim(new Claim("FacebookAccessToken",context.AccessToken)); + context.Identity.AddClaim(new Claim("FacebookAccessToken", context.AccessToken)); return Task.FromResult(true); } }; app.UseFacebookAuthentication(fbAuthOptions); + app.UseGoogleAuthentication( clientId: ConfigurationManager.AppSettings["googleClientId"], clientSecret: ConfigurationManager.AppSettings["googleClientSecret"] ); + + app.UseLinkedInAuthentication(new LinkedInAuthenticationOptions + { + ClientId = ConfigurationManager.AppSettings["linkedinClientId"], + ClientSecret = ConfigurationManager.AppSettings["linkedinClientSecret"] + }); } } } \ No newline at end of file diff --git a/EmpleoDotNet/Base_Auth.config b/EmpleoDotNet/Base_Auth.config index 8af6f795..dfb70db0 100644 --- a/EmpleoDotNet/Base_Auth.config +++ b/EmpleoDotNet/Base_Auth.config @@ -12,4 +12,6 @@ + + \ No newline at end of file diff --git a/EmpleoDotNet/EmpleoDotNet.csproj b/EmpleoDotNet/EmpleoDotNet.csproj index 0e609123..351fc45b 100644 --- a/EmpleoDotNet/EmpleoDotNet.csproj +++ b/EmpleoDotNet/EmpleoDotNet.csproj @@ -135,6 +135,10 @@ ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll True + + ..\packages\Owin.Security.Providers.1.27\lib\net45\Owin.Security.Providers.dll + True + ..\packages\reCAPTCH.MVC.1.0.1\lib\net45\reCAPTCHA.MVC.dll True diff --git a/EmpleoDotNet/Views/Account/_ExternalLoginsListPartial.cshtml b/EmpleoDotNet/Views/Account/_ExternalLoginsListPartial.cshtml index dbc81f6d..bcff6721 100644 --- a/EmpleoDotNet/Views/Account/_ExternalLoginsListPartial.cshtml +++ b/EmpleoDotNet/Views/Account/_ExternalLoginsListPartial.cshtml @@ -4,7 +4,7 @@
-

Inicia sesión

+

Inicia sesión

@@ -23,7 +23,7 @@ { string action = Model.Action; string returnUrl = Model.ReturnUrl; - using (Html.BeginForm(action, "Account", new {ReturnUrl = returnUrl})) + using (Html.BeginForm(action, "Account", new { ReturnUrl = returnUrl })) { @Html.AntiForgeryToken()
@@ -55,6 +55,12 @@ Accede con Twitter } + else if (p.AuthenticationType == "LinkedIn") + { + + } else {