Skip to content

Commit 8259a58

Browse files
authored
Merge pull request #12 from dlmelendez/rel/v3.0
Rel/v3.0
2 parents de99c3a + fecc844 commit 8259a58

File tree

423 files changed

+26569
-1846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

423 files changed

+26569
-1846
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29503.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{76E6FCF1-1099-40C3-BAEB-AA6345DE180A}"
7+
ProjectSection(SolutionItems) = preProject
8+
.gitignore = .gitignore
9+
LICENSE = LICENSE
10+
README.md = README.md
11+
EndProjectSection
12+
EndProject
13+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElCamino.AspNetCore.Identity.CosmosDB", "src\ElCamino.AspNetCore.Identity.CosmosDB\ElCamino.AspNetCore.Identity.CosmosDB.csproj", "{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}"
14+
EndProject
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElCamino.AspNetCore.Identity.CosmosDB.Tests", "tests\ElCamino.AspNetCore.Identity.CosmosDB.Tests\ElCamino.AspNetCore.Identity.CosmosDB.Tests.csproj", "{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}"
16+
EndProject
17+
Global
18+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
19+
Debug|Any CPU = Debug|Any CPU
20+
Debug|x64 = Debug|x64
21+
Debug|x86 = Debug|x86
22+
Release|Any CPU = Release|Any CPU
23+
Release|x64 = Release|x64
24+
Release|x86 = Release|x86
25+
EndGlobalSection
26+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
27+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Debug|x64.ActiveCfg = Debug|Any CPU
30+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Debug|x64.Build.0 = Debug|Any CPU
31+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Debug|x86.ActiveCfg = Debug|Any CPU
32+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Debug|x86.Build.0 = Debug|Any CPU
33+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Release|x64.ActiveCfg = Release|Any CPU
36+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Release|x64.Build.0 = Release|Any CPU
37+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Release|x86.ActiveCfg = Release|Any CPU
38+
{311A8C71-9E5D-434D-BE8A-27ABBB820F5C}.Release|x86.Build.0 = Release|Any CPU
39+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Debug|x64.ActiveCfg = Debug|Any CPU
42+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Debug|x64.Build.0 = Debug|Any CPU
43+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Debug|x86.ActiveCfg = Debug|Any CPU
44+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Debug|x86.Build.0 = Debug|Any CPU
45+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Release|x64.ActiveCfg = Release|Any CPU
48+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Release|x64.Build.0 = Release|Any CPU
49+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Release|x86.ActiveCfg = Release|Any CPU
50+
{0279C5B2-8E9B-4D50-9F89-E35F15FFB3A0}.Release|x86.Build.0 = Release|Any CPU
51+
EndGlobalSection
52+
GlobalSection(SolutionProperties) = preSolution
53+
HideSolutionNode = FALSE
54+
EndGlobalSection
55+
GlobalSection(ExtensibilityGlobals) = postSolution
56+
SolutionGuid = {F619F8B3-37B9-4282-81EB-FAAC236C702E}
57+
EndGlobalSection
58+
EndGlobal

ElCamino.AspNetCore.Identity.DocumentDB.sln

Lines changed: 0 additions & 55 deletions
This file was deleted.

README.md

Lines changed: 94 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,49 @@
1-
# identitycoredocumentdb
1+
# identitycosmosdb
22

3-
This project is an open source high performance plugin to ASP.NET Core Identity framework using Azure CosmosDB/DocumentDB.
3+
This project is an open source high performance plugin to ASP.NET Core Identity framework using Azure CosmosDB.
44

55
[![NuGet Badge](https://buildstats.info/nuget/ElCamino.AspNetCore.Identity.DocumentDB)](https://www.nuget.org/packages/ElCamino.AspNetCore.Identity.DocumentDB/)
6+
[![NuGet Badge](https://buildstats.info/nuget/ElCamino.AspNetCore.Identity.CosmosDB)](https://www.nuget.org/packages/ElCamino.AspNetCore.Identity.CosmosDB/)
67

7-
Identity Core 3.x - Use ElCamino.AspNetCore.Identity.DocumentDB, sample Mvc app: https://github.com/dlmelendez/identitycoredocumentdb/tree/master/sample/samplecore3.mvc
8+
Identity Core 3.x - Use ElCamino.AspNetCore.Identity.CosmosDB, sample Mvc app: https://github.com/dlmelendez/identitycosmosdb/tree/master/sample/samplecore3.mvc
89

9-
Identity Core 2.x - Use ElCamino.AspNetCore.Identity.DocumentDB, sample Mvc app: https://github.com/dlmelendez/identitycoredocumentdb/tree/master/sample/samplecore2.mvc
10+
Identity Core 2.x - Use ElCamino.AspNetCore.Identity.DocumentDB, sample Mvc app: https://github.com/dlmelendez/identitycosmosdb/tree/master/sample/samplecore3.mvc
1011

11-
Identity Core 1.x - Use ElCamino.AspNetCore.Identity.DocumentDB, sample Mvc app: https://github.com/dlmelendez/identitycoredocumentdb/tree/master/sample/samplecore.mvc
12+
Identity Core 1.x - Use ElCamino.AspNetCore.Identity.DocumentDB, sample Mvc app: https://github.com/dlmelendez/identitycosmosdb/tree/master/sample/samplecore.mvc
1213

13-
## Quick Start for Identity Core 2
14+
## Breaking changes to v3.0
15+
### Naming changes from DocumentDB to CosmosDB
16+
- Namespace change from **ElCamino.AspNetCore.Identity.DocumentDB** to **ElCamino.AspNetCore.Identity.CosmosDB**
17+
- Any class, method or configuration key has been changed from **DocumentDB** to **CosmosDB**
18+
### Data Migration
19+
For existing data using ElCamino.AspNetCore.Identity.DocumentDB < v3.0, you should create a new container for the v3.0 configuration and then copy documents to the new container adding "/partitionKey" for the partition key. The partition key should be the last 4 characters of the id field.
20+
21+
Existing document:
22+
```json
23+
{
24+
"id": "abc5cf45-1781-4f56-a9f0-abc64ffbef0f",
25+
"_rid": "MBxvAOomeosCAAAAAAAAAA==",
26+
"_self": "dbs/MBxvAA==/colls/MBxvAOomeos=/docs/MBxvAOomeosCAAAAAAAAAA==/",
27+
"_etag": "\"00000000-0000-0000-919d-8fe1789d01d5\"",
28+
"userName": "263225f79db04d99be098bed7bee3e03",
29+
"normalizedUserName": "263225F79DB04D99BE098BED7BEE3E03"
30+
}
31+
```
32+
33+
New document with Partition Key:
34+
```json
35+
{
36+
"id": "abc5cf45-1781-4f56-a9f0-abc64ffbef0f",
37+
"_rid": "MBxvAOomeosCAAAAAAAAAA==",
38+
"_self": "dbs/MBxvAA==/colls/MBxvAOomeos=/docs/MBxvAOomeosCAAAAAAAAAA==/",
39+
"_etag": "\"00000000-0000-0000-919d-8fe1789d01d5\"",
40+
"userName": "263225f79db04d99be098bed7bee3e03",
41+
"normalizedUserName": "263225F79DB04D99BE098BED7BEE3E03",
42+
"partitionKey": "ef0f",
43+
}
44+
```
45+
46+
## Quick Start for Identity Core 3
1447

1548
Download the CosmosDB [emulator](https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator) or setup an [instance in Azure](https://docs.microsoft.com/en-us/azure/cosmos-db/create-documentdb-dotnet).
1649

@@ -19,85 +52,93 @@ Remove the NuGet packages EntityFramework and Microsoft.AspNetCore.Identity.Enti
1952
##### Simplify your project references
2053
```xml
2154
<ItemGroup>
22-
<PackageReference Include="ElCamino.AspNetCore.Identity.DocumentDB" Version="2.0.0" />
23-
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
25-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
26-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
27-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
28-
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
29-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" /> </ItemGroup>
30-
31-
<ItemGroup>
32-
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
33-
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
55+
<PackageReference Include="ElCamino.AspNetCore.Identity.CosmosDB" Version="3.0.0" />
56+
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
57+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
58+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
59+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
3460
</ItemGroup>
3561
```
3662

3763
Remove all using statements referencing EntityFramework.
3864
Delete the /Data/Migrations directory and all files in it.
3965

40-
##### Changes to [/Models/ApplicationUser.cs](https://github.com/dlmelendez/identitycoredocumentdb/blob/master/sample/samplecore2.mvc/Models/ApplicationUser.cs)
66+
##### Changes to [/areas/identity/**.cs](https://github.com/dlmelendez/identitycosmosdb/blob/master/sample/samplecore3.mvc/Areas/Identity/)
67+
68+
Remove: ~~using Microsoft.AspNetCore.Identity.EntityFramework;~~
69+
70+
Add:
4171
```C#
42-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
43-
...
44-
// Add profile data for application users by adding properties to the ApplicationUser class
45-
public class ApplicationUser : IdentityUser
46-
{
47-
}
72+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
4873
```
49-
##### Changes to [/Data/ApplicationDbContext.cs](https://github.com/dlmelendez/identitycoredocumentdb/blob/master/sample/samplecore2.mvc/Data/ApplicationDbContext.cs)
74+
75+
##### Changes to [/*****/****/_ViewImports.cshtml](https://github.com/dlmelendez/identitycosmosdb/blob/master/sample/samplecore3.mvc/)
76+
77+
Add this using to override the IdentityUser class in the Microsoft.AspNetCore.Identity namespace.
5078
```C#
51-
using ElCamino.AspNetCore.Identity.DocumentDB;
52-
using ElCamino.AspNetCore.Identity.DocumentDB.Model;
79+
@using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser
80+
```
81+
82+
##### Changes to [/Data/ApplicationDbContext.cs](https://github.com/dlmelendez/identitycosmosdb/blob/master/sample/samplecore3.mvc/Data/ApplicationDbContext.cs)
83+
```C#
84+
using ElCamino.AspNetCore.Identity.CosmosDB;
85+
using ElCamino.AspNetCore.Identity.CosmosDB.Model;
5386
...
5487
public class ApplicationDbContext : IdentityCloudContext
5588
{
5689
public ApplicationDbContext(IdentityConfiguration config) : base(config) { }
5790
}
5891
```
59-
##### Changes to [/Startup.cs](https://github.com/dlmelendez/identitycoredocumentdb/blob/master/sample/samplecore2.mvc/Startup.cs)
92+
##### Changes to [/Startup.cs](https://github.com/dlmelendez/identitycosmosdb/blob/master/sample/samplecore3.mvc/Startup.cs)
6093
```c#
61-
using ElCamino.AspNetCore.Identity.DocumentDB.Model;
94+
using ElCamino.AspNetCore.Identity.CosmosDB.Model;
6295
using Microsoft.Azure.Documents.Client;
63-
using IdentityRole = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityRole;
96+
using IdentityRole = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityRole;
6497
...
6598
public class Startup
6699
{
67100
...
68101
// This method gets called by the runtime. Use this method to add services to the container.
69102
public void ConfigureServices(IServiceCollection services)
70103
{
71-
services.AddIdentity<ApplicationUser, IdentityRole>()
72-
.AddDocumentDBStores<ApplicationDbContext>(() =>
73-
{
74-
return new IdentityConfiguration()
75-
{
76-
Uri = Configuration["IdentityDocumentDB:identityConfiguration:uri"],
77-
AuthKey = Configuration["IdentityDocumentDB:identityConfiguration:authKey"],
78-
Database = Configuration["IdentityDocumentDB:identityConfiguration:database"],
79-
IdentityCollection = Configuration["IdentityDocumentDB:identityConfiguration:identityCollection"],
80-
Policy = new ConnectionPolicy()
81-
{
82-
ConnectionMode = ConnectionMode.Gateway,
83-
ConnectionProtocol = Protocol.Https
84-
}
85-
};
86-
}).AddDefaultTokenProviders();
104+
//services.AddDbContext<ApplicationDbContext>(options =>
105+
// options.UseSqlServer(
106+
// Configuration.GetConnectionString("DefaultConnection")));
107+
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
108+
.AddCosmosDBStores<ApplicationDbContext>(() =>
109+
{
110+
return new IdentityConfiguration()
111+
{
112+
Uri = Configuration["IdentityCosmosDB:identityConfiguration:uri"],
113+
AuthKey = Configuration["IdentityCosmosDB:identityConfiguration:authKey"],
114+
Database = Configuration["IdentityCosmosDB:identityConfiguration:database"],
115+
IdentityCollection = Configuration["IdentityCosmosDB:identityConfiguration:identityCollection"],
116+
Options = new CosmosClientOptions()
117+
{
118+
ConnectionMode = ConnectionMode.Gateway,
119+
ConsistencyLevel = ConsistencyLevel.Session,
120+
SerializerOptions = new CosmosSerializationOptions()
121+
{
122+
PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
123+
}
124+
}
125+
};
126+
})
127+
.CreateCosmosDBIfNotExists<ApplicationDbContext>(); //can remove after first run;
128+
//.AddEntityFrameworkStores<ApplicationDbContext>();
129+
services.AddRazorPages();
87130
...
88131
```
89-
##### Changes to [/appsettings.json](https://github.com/dlmelendez/identitycoredocumentdb/blob/master/sample/samplecore2.mvc/appsettings.json)
132+
##### Changes to [/appsettings.json](https://github.com/dlmelendez/identitycosmosdb/blob/master/sample/samplecore3.mvc/appsettings.json)
90133
Defaults for the local CosmosDB emulator. database and collection need to follow the CosmosDB naming rules, otherwise use whatever you like.
91134
```json
92135
{
93-
...
94-
"IdentityDocumentDB": {
136+
137+
"IdentityCosmosDB": {
95138
"identityConfiguration": {
96139
"uri": "https://localhost:8081",
97140
"authKey": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
98141
"database": "Id",
99-
"identityCollection": "users"
142+
"identityCollection": "users3"
100143
}
101-
}
102-
...
103144
```

sample/samplecore3.mvc/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.AspNetCore.Mvc;
99
using Microsoft.AspNetCore.Mvc.RazorPages;
1010
using Microsoft.AspNetCore.WebUtilities;
11-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
11+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1212

1313
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1414
{

sample/samplecore3.mvc/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.AspNetCore.Mvc;
99
using Microsoft.AspNetCore.Mvc.RazorPages;
1010
using Microsoft.AspNetCore.WebUtilities;
11-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
11+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1212

1313
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1414
{

sample/samplecore3.mvc/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using Microsoft.AspNetCore.Mvc.RazorPages;
1414
using Microsoft.AspNetCore.WebUtilities;
1515
using Microsoft.Extensions.Logging;
16-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
16+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1717

1818
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1919
{

sample/samplecore3.mvc/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Microsoft.AspNetCore.Mvc;
1111
using Microsoft.AspNetCore.Mvc.RazorPages;
1212
using Microsoft.AspNetCore.WebUtilities;
13-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
13+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1414

1515
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1616
{

sample/samplecore3.mvc/Areas/Identity/Pages/Account/Login.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.AspNetCore.Mvc.RazorPages;
1313
using Microsoft.Extensions.Logging;
14-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
14+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1515

1616
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1717
{

sample/samplecore3.mvc/Areas/Identity/Pages/Account/LoginWith2fa.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.AspNetCore.Mvc;
99
using Microsoft.AspNetCore.Mvc.RazorPages;
1010
using Microsoft.Extensions.Logging;
11-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
11+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1212

1313
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1414
{

sample/samplecore3.mvc/Areas/Identity/Pages/Account/LoginWithRecoveryCode.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.AspNetCore.Mvc;
99
using Microsoft.AspNetCore.Mvc.RazorPages;
1010
using Microsoft.Extensions.Logging;
11-
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser;
11+
using IdentityUser = ElCamino.AspNetCore.Identity.CosmosDB.Model.IdentityUser;
1212

1313
namespace samplecore3.mvc.Areas.Identity.Pages.Account
1414
{

0 commit comments

Comments
 (0)