diff --git a/src/MusicStore/Controllers/AccountController.cs b/src/MusicStore/Controllers/AccountController.cs index 015fec7626..9e3443a3f3 100644 --- a/src/MusicStore/Controllers/AccountController.cs +++ b/src/MusicStore/Controllers/AccountController.cs @@ -270,7 +270,7 @@ namespace MusicStore.Controllers [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] - public ActionResult ExternalLogin(string provider, string returnUrl) + public ActionResult ExternalLogin(string provider, string returnUrl = null) { // Request a redirect to the external login provider var redirectUri = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }); diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 8f670f11dc..64b178ac70 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -9,6 +9,11 @@ using Microsoft.Data.Entity; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using MusicStore.Models; +using Microsoft.AspNet.Security.Facebook; +using Microsoft.AspNet.Security.Google; +using Microsoft.AspNet.Security.Twitter; +using Microsoft.AspNet.Security.MicrosoftAccount; +using Microsoft.AspNet.Security; namespace MusicStore { @@ -26,6 +31,8 @@ namespace MusicStore //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. app.UseErrorPage(ErrorPageOptions.ShowAll); + app.SetDefaultSignInAsAuthenticationType("External"); + app.UseServices(services => { //If this type is present - we're on mono @@ -77,6 +84,14 @@ namespace MusicStore // Add static files to the request pipeline app.UseStaticFiles(); + // Add cookie-based authentication to the request pipeline + app.UseCookieAuthentication(new CookieAuthenticationOptions + { + AuthenticationType = "External", + AuthenticationMode = AuthenticationMode.Passive, + ExpireTimeSpan = TimeSpan.FromMinutes(5) + }); + // Add cookie-based authentication to the request pipeline app.UseCookieAuthentication(new CookieAuthenticationOptions { @@ -86,6 +101,31 @@ namespace MusicStore app.UseTwoFactorSignInCookies(); + app.UseFacebookAuthentication(new FacebookAuthenticationOptions() + { + AppId = "[AppId]", + AppSecret = "[AppSecret]", + }); + + app.UseGoogleAuthentication(new GoogleAuthenticationOptions() + { + ClientId = "[ClientId]", + ClientSecret = "[ClientSecret]", + }); + + app.UseTwitterAuthentication(new TwitterAuthenticationOptions() + { + ConsumerKey = "[ConsumerKey]", + ConsumerSecret = "[ConsumerSecret]", + }); + + app.UseMicrosoftAccountAuthentication(new MicrosoftAccountAuthenticationOptions() + { + Caption = "MicrosoftAccount - Requires project changes", + ClientId = "[ClientId]", + ClientSecret = "[ClientSecret]", + }); + // Add MVC to the request pipeline app.UseMvc(routes => { diff --git a/src/MusicStore/Views/Account/Login.cshtml b/src/MusicStore/Views/Account/Login.cshtml index 0b8cd41a86..27a628c27c 100644 --- a/src/MusicStore/Views/Account/Login.cshtml +++ b/src/MusicStore/Views/Account/Login.cshtml @@ -52,11 +52,11 @@ } - @*
There are no external authentication services configured. See this article @@ -13,12 +14,16 @@
asdfasdf
+ using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) + { @Html.AntiForgeryToken()