Files
RavenDB.Identity/Readme.md
T

87 lines
3.9 KiB
Markdown
Raw Normal View History

2019-03-04 16:58:35 -06:00
# <img src="https://github.com/JudahGabriel/RavenDB.Identity/blob/master/RavenDB.Identity/nuget-icon.png?raw=true" width="50px" height="50px" /> RavenDB.Identity
The simple and easy Identity provider for RavenDB and ASP.NET Core. Use Raven to store your users and logins.
## Instructions ##
***Important:** Upgrading from a previous version of RavenDB.Identity? See <a href="#updating-from-old-version">Updating From Old Version</a> for steps to migrate to the latest RavenDB.Identity.*
2019-03-04 16:58:35 -06:00
1. Add an [AppUser class](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Models/AppUser.cs) that derives from Raven.Identity.IdentityUser:
```csharp
public class AppUser : Raven.Identity.IdentityUser
{
/// <summary>
/// A user's full name.
/// </summary>
public string FullName { get; set; }
}
```
2019-03-04 17:11:14 -06:00
2. In appsettings.json, configure your connection to Raven:
```json
"RavenSettings": {
"Urls": [
"http://live-test.ravendb.net"
],
"DatabaseName": "Raven.Identity.Sample",
"CertFilePath": "",
"CertPassword": ""
},
```
2019-03-04 17:13:26 -06:00
3. In [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Startup.cs), wire it all up:
```csharp
public void ConfigureServices(IServiceCollection services)
{
2019-03-04 17:11:14 -06:00
// Grab our RavenSettings object from appsettings.json.
2019-03-04 16:58:35 -06:00
services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
2019-03-04 17:11:14 -06:00
...
// Add RavenDB and identity.
services
.AddRavenDbDocStore() // Create an IDocumentStore singleton from the RavenSettings.
2019-03-04 17:13:26 -06:00
.AddRavenDbAsyncSession() // Create a RavenDB IAsyncDocumentSession for each request. You're responsible for calling .SaveChanges after each request.
2019-03-04 17:11:14 -06:00
.AddRavenDbIdentity<AppUser>(); // Use Raven to manage users and roles.
...
}
```
2019-03-04 17:17:22 -06:00
4. In your controller actions, [call .SaveChangesAsync() when you're done making changes](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs#L35). Typically this is done via a RavenController base class for MVC/WebAPI projects or via an action filter. See our sample [RavenSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs).
## Modifying RavenDB conventions
To modify RavenDB conventions, you can use the `services.AddRavenDbDocStore(options)` overload:
```csharp
services.AddRavenDbDocStore(options =>
{
options.BeforeInitializeDocStore = docStore => docStore.Conventions.IdentityPartsSeparator = "-";
})
```
## <a id="updating-from-old-version">Updating From Old Version of RavenDB.Identity</a>
Using an old version of RavenDB.Identity and want to upgrade to the latest? You need to call the `MigrateToV6` method:
```csharp
// Update our existing users to the latest RavenDB.Identity v6.
// This is necessary only if you stored users with a previous version of RavenDB.Identity.
// Failure to call this method will result in existing users not being able to login.
// This method can take several minutes if you have thousands of users.
2019-03-21 16:42:56 -05:00
UserStore<AppUser>.MigrateToV6(docStore);
```
This upgrade step is necessary because we [updated RavenDB.Identity to use RavenDB's cluster-safe compare/exchange](https://github.com/JudahGabriel/RavenDB.Identity/issues/5) to enforce user name/email uniqueness.
Previous versions of RavenDB.Identity had relied on `IdentityUserByUserName` IDs to enforce uniqueness, but this isn't guaranteed to work in a cluster. Calling MigrateToV6 will create compare/exchange values in Raven for each email address, and will remove the now-obsolete IdentityUserByUserNames collection.
## Getting Started and Sample Project
2019-03-04 17:11:14 -06:00
Need help? Checkout the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample) to see it all in action.
2017-08-23 15:38:59 -05:00
## Not using .NET Core?
See our [sister project](https://github.com/JudahGabriel/RavenDB.AspNet.Identity) for a RavenDB Identity Provider for the full .NET Framework.