Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5238736
Move to dotnet core
g0t4 Sep 7, 2016
c740ede
Update R# version
g0t4 Sep 7, 2016
8901626
Add in dependencies for MongDB 2.3 rc1 (dotnet core support) and ASP.…
g0t4 Sep 7, 2016
5f99bac
Reworking for ASP.NET Core Identity
g0t4 Sep 7, 2016
d125ccc
Project updates after killing old Identity project
g0t4 Sep 7, 2016
520a790
New core tests project
g0t4 Sep 7, 2016
935353f
Move tests
g0t4 Sep 7, 2016
7870cbc
Add refs to tests
g0t4 Sep 7, 2016
3caa9ba
Getting tests working
g0t4 Sep 7, 2016
b63d8ce
Get test project to compile
g0t4 Sep 7, 2016
69e09d8
target netcoreapp1.0 so we can use the nunit test runner, this is jus…
g0t4 Sep 7, 2016
4e9a4e2
Unused reflection method to SetId, object id is generated in ctor of …
g0t4 Sep 7, 2016
13ef785
New Integration Tests
g0t4 Sep 7, 2016
cc7f97c
Move integration tests
g0t4 Sep 7, 2016
c911957
Get extended role tests working - first set of integration tests - fi…
g0t4 Sep 7, 2016
0b866c1
Port more integration tests
g0t4 Sep 7, 2016
cc4797d
Another batch - with custom lockout settings
g0t4 Sep 7, 2016
7e42dbb
Cleanup
g0t4 Sep 7, 2016
c8f2a4e
Get more tests working - fix user by name to use Normalized Name
g0t4 Sep 7, 2016
f81c51f
Tidying up, notes, disable some warnings for a style of code I'm usin…
g0t4 Sep 8, 2016
2660b13
Notes about display name on logins
g0t4 Sep 8, 2016
aa039ec
project.json options for packing library
g0t4 Sep 8, 2016
a003800
Notes
g0t4 Sep 24, 2016
144e316
Testing role store for simple accessors and getters
g0t4 Sep 24, 2016
b53148e
Testing for role name normalization
g0t4 Sep 24, 2016
f20dee2
Simple getter/setter testing for user
g0t4 Sep 24, 2016
8d07779
Add GetUsersInRole test
g0t4 Sep 24, 2016
0393352
Validated these tests still work of Login functions
g0t4 Sep 24, 2016
c48e2b5
Woops on not awaiting :)
g0t4 Sep 24, 2016
27a8a67
Tests ok
g0t4 Sep 24, 2016
a96b24b
todos to validate tests still work after migration to async... takes…
g0t4 Sep 24, 2016
d4fe88b
tests ok
g0t4 Sep 24, 2016
0411dc5
Add tests for replacing claims
g0t4 Sep 24, 2016
488345f
Add tests for GetUsersForClaimAsync
g0t4 Sep 24, 2016
fb134ec
These are tested
g0t4 Sep 25, 2016
3516928
Add testing of UserAuthenticationTokenStore
g0t4 Sep 25, 2016
70caa46
review todos
g0t4 Sep 25, 2016
5856bbc
Add IdentityUserLogin type to get away from UserLoginInfo in Identity…
g0t4 Sep 25, 2016
ea5af3f
Figure out lowest common denominators for what frameworks I want to s…
g0t4 Sep 27, 2016
806a1f7
Add normalized field unique indexes
g0t4 Sep 27, 2016
0c58cb9
Override ToString to be helpful when debugging
g0t4 Sep 27, 2016
d9fa923
Create AddMongoStores extension method to inject Store services
g0t4 Sep 27, 2016
ad6055a
Continue working on AddMongoStores
g0t4 Sep 27, 2016
6dd8bcc
Considering perspective of consumer, roll up registration into one me…
g0t4 Sep 27, 2016
631d301
Rename AddMongoStores to RegisterMongoStores so it's not in the conve…
g0t4 Sep 27, 2016
733a5c7
Update root README for project
g0t4 Sep 27, 2016
350c9e2
Tweaks to docs
g0t4 Sep 27, 2016
2b5db3e
Simplify description
g0t4 Sep 27, 2016
fc92365
Update build instructions
g0t4 Sep 27, 2016
4e2c4c8
Return IdentityBuilder so consumers can chain subsequent Identity reg…
g0t4 Sep 28, 2016
337e10b
Command for publishing to my local nuget feed
g0t4 Sep 28, 2016
e6f1e41
Release v1.0.1
g0t4 Sep 28, 2016
fb63d34
If an invalid objectid is passed to FindById, we return null as if th…
g0t4 Sep 28, 2016
4436871
Cleaning up build script
g0t4 Sep 28, 2016
43f749c
Go back to storing LockoutEndDateUtc as DateTime for sorting purposes…
g0t4 Oct 1, 2016
88318b7
VS 15.x & .Net standard 2.0
Aug 31, 2017
3890c11
Merge remote-tracking branch 'g0t4/master' into netcore
Oct 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/artifacts/

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

Expand Down Expand Up @@ -154,4 +156,9 @@ $RECYCLE.BIN/

# Mac desktop service store files
.DS_Store
/TestResult.xml

TestResult.xml

project.lock.json

.vs/
81 changes: 43 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
AspNet.Identity.Mongo
=====================
## Microsoft.AspNetCore.Identity.MongoDB

A mongodb provider for the new ASP.NET Identity framework. My aim is to ensure this project is well tested and configurable.
This is a MongoDB provider for the ASP.NET Core Identity framework. This was ported from the v2 Identity framework that was a part of ASP.NET (AspNet.Identity.Mongo NuGet package)

## Usage

var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("mydb");
var users = database.GetCollection<IdentityUser>("users");

var store = new UserStore<IdentityUser>(users);
var manager = new UserManager<IdentityUser>(store);
I've released a new package for the ASP.NET Core Identity framework for the following reasons:
- Discoverability - named AspNetCore.
- ASP.NET Core is a rewrite of ASP.NET, this Core Identity framework won't run on traditional ASP.NET.
- Migrating isn't a matter of updating dependencies.

// if you want roles too:
var roles = database.GetCollection<IdentityRole>("roles");
var roleStore = new RoleStore<IdentityRole>(roles);
This project has extensive test coverage.

// at some point in application startup it would be good to ensure unique indexes on user and role names exist:
If you want something easy to setup, this adapter is for you. I do not intend to cover every possible desirable configuration, if you don't like my decisions, write your own adapter. Use this as a learning tool to make your own adapter. These adapters are not complicated, but trying to make them configurable would become a complicated mess. And would confuse the majority of people that want something simple to use. So I'm favoring simplicity over making every last person happy.

IndexChecks.EnsureUniqueIndexOnUserName(users);
IndexChecks.EnsureUniqueIndexOnEmail(users);

IndexChecks.EnsureUniqueIndexOnRoleName(roles);

OR
## Usage

a sample [aspnet-identity-mongo-sample](https://github.com/g0t4/aspnet-identity-mongo-sample) based on [Microsoft ASP.NET Identity Samples](http://www.nuget.org/packages/Microsoft.AspNet.Identity.Samples).
- Reference this package in project.json: Microsoft.AspNetCore.Identity.MongoDB
- Then, in ConfigureServices--or wherever you are registering services--include the following to register both the Identity services and MongoDB stores:

## Installation
```csharp
services.AddIdentityWithMongoStores("mongodb://localhost/myDB");
```

via nuget:
- If you want to customize what is registered, refer to the tests for further options (CoreTests/MongoIdentityBuilderExtensionsTests.cs)
- Remember with the Identity framework, the whole point is that both a `UserManager` and `RoleManager` are provided for you to use, here's how you can resolve instances manually. Of course, constructor injection is also available.

Install-Package AspNet.Identity.MongoDB
```csharp
var userManager = provider.GetService<UserManager<IdentityUser>>();
var roleManager = provider.GetService<RoleManager<IdentityRole>>();
```

## Building and Testing
- The following methods help create indexes that will boost lookups by UserName, Email and role Name. These have changed since Identity v2 to refer to Normalized fields. I dislike this aspect of Core Identity, but it is what it is. Basically these three fields are stored in uppercase format for case insensitive searches.

I'm using the albacore project with rake.
```csharp
IndexChecks.EnsureUniqueIndexOnNormalizedUserName(users);
IndexChecks.EnsureUniqueIndexOnNormalizedEmail(users);
IndexChecks.EnsureUniqueIndexOnNormalizedRoleName(roles);
```

To build:
- Here is a sample project, review the commit log for the steps taken to port the default template from EntityFramework MSSQL to MongoDB. [aspnet-identity-mongo-sample](https://github.com/g0t4/aspnet-identity-mongo-sample).

rake msbuild

To test:
What frameworks are targeted, with rationale:

rake tests
rake integration_tests
- Microsoft.AspNetCore.Identity - supports net451 and netstandard1.3
- MongoDB.Driver v2.3 - supports net45 and netstandard1.5
- Thus, the lowest common denominators are net451 (of net45 and net451) and netstandard1.5 (of netstandard1.3 and netstandard1.5)
- FYI net451 supports netstandard1.2, that's obviously too low for a single target

To package:

rake package
## Building instructions

## Documentation
run commands in [](build.sh)

I'm writing about my design decisions on my blog:
## Migrating from ASP.NET Identity 2.0

<<<<<<< HEAD
- Roles names need to be normalized as follows
- On IdentityRole documents, create a NormalizedName field = uppercase(Name). Leave Name as is.
- On IdentityUser documents, convert the values in the Roles array to uppercase
- User names need to be normalized as follows
- On IdentityUser documents, create a NormalizedUserName field = uppercase(UserName) and create a NormalizedEmail field = uppercase(Email). Leave UserName and Email as is.
=======
- [Building a mongodb provider for the new ASP.NET Identity framework - Part 1](http://devblog.weshigbee.name/posts/building-a-mongodb-provider-for-the-new-asp.net-identity-framework-part-1)
- [Building a mongodb provider for the new ASP.NET Identity framework - Part 2 RoleStore And Sample](http://devblog.weshigbee.name/posts/building-a-mongodb-provider-for-the-new-asp.net-identity-framework-part-2-rolestore-and-sample)
>>>>>>> g0t4/master
23 changes: 0 additions & 23 deletions Rakefile.rb

This file was deleted.

10 changes: 10 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
REM optional clean
REM rm -rf artifacts CoreTests/bin CoreTests/obj CoreIntegrationTests/bin CoreIntegrationTests/obj Microsoft.AspNetCore.Identity.MongoDB/bin Microsoft.AspNetCore.Identity.MongoDB/obj

dotnet restore src
dotnet test -c Release src/CoreTests
dotnet test -c Release src/CoreIntegrationTests
dotnet pack -c Release -o artifacts src/Microsoft.AspNetCore.Identity.MongoDB

REM nuget add artifacts\X.nupkg -Source C:\Code\scratch\localnugetfeedtesting
REM nuget publish artifacts\X.nupkg
37 changes: 20 additions & 17 deletions src/AspNet.Identity.MongoDB.sln
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Identity.MongoDB", "AspNet.Identity.MongoDB\AspNet.Identity.MongoDB.csproj", "{AD64128A-6855-49F7-A846-1FCDAD368C55}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreTests", "CoreTests\CoreTests.csproj", "{EAC53866-6DBF-40B7-900A-22267FD0634A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{62483144-11D8-4ECE-990D-17B4716AFF69}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Identity.MongoDB", "Microsoft.AspNetCore.Identity.MongoDB\Microsoft.AspNetCore.Identity.MongoDB.csproj", "{6DFF5058-E107-459E-87C3-DA41B2C1463C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "IntegrationTests\IntegrationTests.csproj", "{2817B6BF-006D-415D-8CAB-34E14DCCBC3C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreIntegrationTests", "CoreIntegrationTests\CoreIntegrationTests.csproj", "{836F4635-9B6B-4090-8CDB-9CD9F7BEA829}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD64128A-6855-49F7-A846-1FCDAD368C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD64128A-6855-49F7-A846-1FCDAD368C55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD64128A-6855-49F7-A846-1FCDAD368C55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD64128A-6855-49F7-A846-1FCDAD368C55}.Release|Any CPU.Build.0 = Release|Any CPU
{62483144-11D8-4ECE-990D-17B4716AFF69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62483144-11D8-4ECE-990D-17B4716AFF69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62483144-11D8-4ECE-990D-17B4716AFF69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62483144-11D8-4ECE-990D-17B4716AFF69}.Release|Any CPU.Build.0 = Release|Any CPU
{2817B6BF-006D-415D-8CAB-34E14DCCBC3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2817B6BF-006D-415D-8CAB-34E14DCCBC3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2817B6BF-006D-415D-8CAB-34E14DCCBC3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2817B6BF-006D-415D-8CAB-34E14DCCBC3C}.Release|Any CPU.Build.0 = Release|Any CPU
{EAC53866-6DBF-40B7-900A-22267FD0634A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAC53866-6DBF-40B7-900A-22267FD0634A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAC53866-6DBF-40B7-900A-22267FD0634A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAC53866-6DBF-40B7-900A-22267FD0634A}.Release|Any CPU.Build.0 = Release|Any CPU
{6DFF5058-E107-459E-87C3-DA41B2C1463C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DFF5058-E107-459E-87C3-DA41B2C1463C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DFF5058-E107-459E-87C3-DA41B2C1463C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DFF5058-E107-459E-87C3-DA41B2C1463C}.Release|Any CPU.Build.0 = Release|Any CPU
{836F4635-9B6B-4090-8CDB-9CD9F7BEA829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{836F4635-9B6B-4090-8CDB-9CD9F7BEA829}.Debug|Any CPU.Build.0 = Debug|Any CPU
{836F4635-9B6B-4090-8CDB-9CD9F7BEA829}.Release|Any CPU.ActiveCfg = Release|Any CPU
{836F4635-9B6B-4090-8CDB-9CD9F7BEA829}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F4D69225-2814-4DFF-93D6-7AA341335C1C}
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion src/AspNet.Identity.MongoDB.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Shared/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Shared"&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;CSArrangeThisQualifier&gt;True&lt;/CSArrangeThisQualifier&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;CAN_CHANGE_TO_IMPLICIT&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;ALWAYS_IMPLICIT&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_IMPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsFormatDocComments&gt;True&lt;/JsFormatDocComments&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Shared</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
80 changes: 0 additions & 80 deletions src/AspNet.Identity.MongoDB/AspNet.Identity.MongoDB.csproj

This file was deleted.

17 changes: 0 additions & 17 deletions src/AspNet.Identity.MongoDB/AspNet.Identity.MongoDB.nuspec

This file was deleted.

Loading