Elastic-Identity wires up the storage and repository of ElasticSearch with ASP.NET Identity
- 1.0.2
- Target NEST 1.0.x
- 1.0.0-rc2
- Fixed version problem with NEST dependency
- 1.0.0-rc1
- Added support for additional services:
- IUserTwoFactorStore
- IUserEmailStore
- IUserPhoneNumberStore
- Upgrade to ASP.NET Identity 2.x
- Upgrade to support Nest 1.x
- Breaking change in constructor, no more seed parameter, users should override SeedAsync() instead
- Added support for additional services:
Get it from nuget.org
new ElasticUserStore<ElasticUser>( new Uri( "http://localhost:9200/" ) );
builder.Register( c => new ElasticUserStore<ElasticUser>( Settings.Default.UserServer ) )
.AsSelf()
.AsImplementedInterfaces()
.SingleInstance();
You should probably consume IUserStore in your code
public class MyElasticUserStore<TUser> : ElasticUserStore<TUser>
{
public MyElasticUserStore( Uri connectionString ) : base( connectionString )
{
}
static readonly string[] _roles =
{
"Admin",
"User",
...
};
const string _seedUser = "elonmusk";
const string _seedPassword = "tesla";
protected override async Task SeedAsync()
{
var user = new ElasticUser {
UserName = _seedUser
};
user.Roles.UnionWith( _roles );
var userManager = new UserManager<ElasticUser>( this );
await userManager.CreateAsync( user, _seedPassword );
}
}
builder.Register( c => new MyElasticUserStore<ElasticUser>( Settings.Default.UserServer ) )
.AsSelf()
.AsImplementedInterfaces()
.SingleInstance();
public enum Transportation {
Roadster,
ModelS,
Other
}
public class MyUser : ElasticUser
{
public string Twitter { get; set; }
public Transportation Car { get; set; }
}
new ElasticUserStore<MyUser>( new Uri( "http://localhost:9200/" ) );
The code is pretty tiny, so go ahead and explore the source code to find out what's possible. Also, check out the options of the ElasticUserStore constructor
ElasticUserStore(
Uri connectionString, // where's your elasticsearch. Something like http://localhost:9200/ or http://users.tesla-co.internal/
string indexName = "users", // what index we're storing the users under. Defaults to "users"
string entityName = "user", // type name for each user. Defaults to "user"
bool forceRecreate = false // if index exists, drop it before creating it again.
)
protected override async Task SeedAsync()
{
// Put your seeding logic here, stuff that's
// executed when the index is created
}
Yes please
Thanks to tstojecki for the NEST-RC1 upgrade
elastic-identity is licenced under the MIT license. Refer to LICENSE for more information.