Adding all the Social login middlewares to the pipeline

Still some of the identity helpers have not lighted up. So it will not work fully.
This commit is contained in:
Praburaj 2014-09-03 16:57:38 -07:00
parent 265a220142
commit 6cf7cbfa5b
5 changed files with 59 additions and 10 deletions

View File

@ -270,7 +270,7 @@ namespace MusicStore.Controllers
[HttpPost] [HttpPost]
[AllowAnonymous] [AllowAnonymous]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl) public ActionResult ExternalLogin(string provider, string returnUrl = null)
{ {
// Request a redirect to the external login provider // Request a redirect to the external login provider
var redirectUri = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }); var redirectUri = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });

View File

@ -9,6 +9,11 @@ using Microsoft.Data.Entity;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using MusicStore.Models; 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 namespace MusicStore
{ {
@ -26,6 +31,8 @@ namespace MusicStore
//Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseErrorPage(ErrorPageOptions.ShowAll);
app.SetDefaultSignInAsAuthenticationType("External");
app.UseServices(services => app.UseServices(services =>
{ {
//If this type is present - we're on mono //If this type is present - we're on mono
@ -77,6 +84,14 @@ namespace MusicStore
// Add static files to the request pipeline // Add static files to the request pipeline
app.UseStaticFiles(); 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 // Add cookie-based authentication to the request pipeline
app.UseCookieAuthentication(new CookieAuthenticationOptions app.UseCookieAuthentication(new CookieAuthenticationOptions
{ {
@ -86,6 +101,31 @@ namespace MusicStore
app.UseTwoFactorSignInCookies(); 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 // Add MVC to the request pipeline
app.UseMvc(routes => app.UseMvc(routes =>
{ {

View File

@ -52,11 +52,11 @@
} }
</section> </section>
</div> </div>
@*<div class="col-md-4"> <div class="col-md-4">
<section id="socialLoginForm"> <section id="socialLoginForm">
@Html.PartialAsync("_ExternalLoginsListPartial", new ExternalLoginListViewModel { ReturnUrl = ViewBag.ReturnUrl }) @await Html.PartialAsync("_ExternalLoginsListPartial", new ExternalLoginListViewModel { ReturnUrl = ViewBag.ReturnUrl })
</section> </section>
</div>*@ </div>
</div> </div>
@section Scripts { @section Scripts {
@*TODO : Until script helpers are available, adding script references manually*@ @*TODO : Until script helpers are available, adding script references manually*@

View File

@ -5,7 +5,8 @@
<hr /> <hr />
@{ @{
var loginProviders = Context.GetAuthenticationTypes(); var loginProviders = Context.GetAuthenticationTypes();
if (loginProviders.Count() == 0) { if (loginProviders.Count() == 0)
{
<div> <div>
<p> <p>
There are no external authentication services configured. See <a href="http://go.microsoft.com/fwlink/?LinkId=313242">this article</a> There are no external authentication services configured. See <a href="http://go.microsoft.com/fwlink/?LinkId=313242">this article</a>
@ -13,12 +14,16 @@
</p> </p>
</div> </div>
} }
else { else
using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) { {
<p>asdfasdf</p>
using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl }))
{
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
<div id="socialLoginList"> <div id="socialLoginList">
<p> <p>
@foreach (AuthenticationDescription p in loginProviders) { @foreach (AuthenticationDescription p in loginProviders)
{
<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button> <button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
} }
</p> </p>

View File

@ -14,6 +14,10 @@
"Microsoft.AspNet.Identity.SqlServer": "3.0.0-*", "Microsoft.AspNet.Identity.SqlServer": "3.0.0-*",
"Microsoft.AspNet.Identity.Authentication": "3.0.0-*", "Microsoft.AspNet.Identity.Authentication": "3.0.0-*",
"Microsoft.AspNet.Security.Cookies": "1.0.0-*", "Microsoft.AspNet.Security.Cookies": "1.0.0-*",
"Microsoft.AspNet.Security.Facebook": "1.0.0-*",
"Microsoft.AspNet.Security.Google": "1.0.0-*",
"Microsoft.AspNet.Security.MicrosoftAccount": "1.0.0-*",
"Microsoft.AspNet.Security.Twitter": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*",
"EntityFramework.SqlServer": "7.0.0-*", "EntityFramework.SqlServer": "7.0.0-*",
/*For Mono*/ /*For Mono*/