Two factor auth fully working in the sample project.
This commit is contained in:
@@ -105,6 +105,7 @@ namespace Raven.Identity
|
||||
this.Claims = new List<IdentityUserClaim>();
|
||||
this.Roles = new List<string>();
|
||||
this.Logins = new List<UserLoginInfo>();
|
||||
this.TwoFactorRecoveryCodes = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,7 +11,7 @@ public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add RavenDB and identity.
|
||||
services
|
||||
.AddRavenDbAsyncSession(docStore) // Create a RavenDB IAsyncDocumentSession for each request. docStore is your IDocumentStore instance.
|
||||
.AddRavenDbAsyncSession(docStore) // Create a RavenDB IAsyncDocumentSession for each request. docStore is your IDocumentStore instance. You're responsible for calling .SaveChanges after each request.
|
||||
.AddRavenDbIdentity<AppUser>(); // Use Raven for users and roles. AppUser is your class, a simple DTO to hold user data. See https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Models/AppUser.cs
|
||||
|
||||
...
|
||||
@@ -22,6 +22,6 @@ public void ConfigureServices(IServiceCollection services)
|
||||
|
||||
3. You're done!
|
||||
|
||||
Need help? See the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample).
|
||||
Need help? See the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample). It supports regular sign-ins as well as 2-factor authentication.
|
||||
|
||||
Not using .NET Core? See our [sister project](https://github.com/JudahGabriel/RavenDB.AspNet.Identity) for a RavenDB Identity Provider for MVC 5+ and WebAPI 2+ on the full .NET Framework.
|
||||
@@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Raven.Client.Documents.Session;
|
||||
using Sample.Models;
|
||||
using Sample.Models.ManageViewModels;
|
||||
using Sample.Services;
|
||||
@@ -18,7 +19,7 @@ namespace Sample.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("[controller]/[action]")]
|
||||
public class ManageController : Controller
|
||||
public class ManageController : RavenController
|
||||
{
|
||||
private readonly UserManager<AppUser> _userManager;
|
||||
private readonly SignInManager<AppUser> _signInManager;
|
||||
@@ -29,11 +30,13 @@ namespace Sample.Controllers
|
||||
private const string AuthenicatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
|
||||
|
||||
public ManageController(
|
||||
UserManager<AppUser> userManager,
|
||||
SignInManager<AppUser> signInManager,
|
||||
IEmailSender emailSender,
|
||||
ILogger<ManageController> logger,
|
||||
UrlEncoder urlEncoder)
|
||||
IAsyncDocumentSession dbSession,
|
||||
UserManager<AppUser> userManager,
|
||||
SignInManager<AppUser> signInManager,
|
||||
IEmailSender emailSender,
|
||||
ILogger<ManageController> logger,
|
||||
UrlEncoder urlEncoder)
|
||||
: base(dbSession)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_signInManager = signInManager;
|
||||
|
||||
+21
-18
@@ -29,29 +29,14 @@ namespace Sample
|
||||
{
|
||||
|
||||
// Connect to a Raven server. We're using the public test playground at http://live-test.ravendb.net
|
||||
// NOTE: Getting a DatabaseDoesNotExistException? Go to http://live-test.ravendb.net and create a database with the name 'Raven.Identity.Sample'
|
||||
var databaseName = "Raven.Identity.Sample";
|
||||
var docStore = new DocumentStore
|
||||
{
|
||||
Urls = new string[] { "http://live-test.ravendb.net" },
|
||||
Database = "Raven.Identity.Sample"
|
||||
Database = databaseName
|
||||
};
|
||||
docStore.Initialize();
|
||||
|
||||
// Create the database if it doesn't exist yet.
|
||||
try
|
||||
{
|
||||
using (var dbSession = docStore.OpenSession())
|
||||
{
|
||||
dbSession.Query<AppUser>().Take(0).ToList();
|
||||
}
|
||||
}
|
||||
catch (Raven.Client.Exceptions.Database.DatabaseDoesNotExistException)
|
||||
{
|
||||
docStore.Maintenance.Server.Send(new Raven.Client.ServerWide.Operations.CreateDatabaseOperation(new Raven.Client.ServerWide.DatabaseRecord
|
||||
{
|
||||
DatabaseName = "Raven.Identity.Sample"
|
||||
}));
|
||||
}
|
||||
CreateDatabaseIfNotExists(docStore, databaseName);
|
||||
|
||||
// Add RavenDB and identity.
|
||||
services
|
||||
@@ -67,6 +52,24 @@ namespace Sample
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
private void CreateDatabaseIfNotExists(IDocumentStore docStore, string databaseName)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var dbSession = docStore.OpenSession())
|
||||
{
|
||||
dbSession.Query<AppUser>().Take(0).ToList();
|
||||
}
|
||||
}
|
||||
catch (Raven.Client.Exceptions.Database.DatabaseDoesNotExistException)
|
||||
{
|
||||
docStore.Maintenance.Server.Send(new Raven.Client.ServerWide.Operations.CreateDatabaseOperation(new Raven.Client.ServerWide.DatabaseRecord
|
||||
{
|
||||
DatabaseName = databaseName
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user