Extended identity api so that the AspNetUsers table also contains a column called TenantId, so that this can be used to check what tenant a user belongs to.

This commit is contained in:
espent1004 2020-02-01 19:47:35 +01:00
parent 71e52e9f89
commit 0365b52e66
6 changed files with 50 additions and 5 deletions

View File

@ -74,7 +74,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
"cardholdername", "cardnumber", "cardtype", "city", "country", "cardholdername", "cardnumber", "cardtype", "city", "country",
"email", "expiration", "lastname", "name", "phonenumber", "email", "expiration", "lastname", "name", "phonenumber",
"username", "zipcode", "state", "street", "securitynumber", "username", "zipcode", "state", "street", "securitynumber",
"normalizedemail", "normalizedusername", "password" "normalizedemail", "normalizedusername", "password", "tenantid"
}; };
csvheaders = GetHeaders(requiredHeaders, csvFileUsers); csvheaders = GetHeaders(requiredHeaders, csvFileUsers);
} }
@ -104,11 +104,17 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
} }
string cardtypeString = column[Array.IndexOf(headers, "cardtype")].Trim('"').Trim(); string cardtypeString = column[Array.IndexOf(headers, "cardtype")].Trim('"').Trim();
string tenantIdString = column[Array.IndexOf(headers, "tenantid")].Trim('"').Trim();
if (!int.TryParse(cardtypeString, out int cardtype)) if (!int.TryParse(cardtypeString, out int cardtype))
{ {
throw new Exception($"cardtype='{cardtypeString}' is not a number"); throw new Exception($"cardtype='{cardtypeString}' is not a number");
} }
if (!int.TryParse(tenantIdString, out int tenantId))
{
throw new Exception($"tenantid='{tenantIdString}' is not a number");
}
var user = new ApplicationUser var user = new ApplicationUser
{ {
CardHolderName = column[Array.IndexOf(headers, "cardholdername")].Trim('"').Trim(), CardHolderName = column[Array.IndexOf(headers, "cardholdername")].Trim('"').Trim(),
@ -131,6 +137,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
NormalizedUserName = column[Array.IndexOf(headers, "normalizedusername")].Trim('"').Trim(), NormalizedUserName = column[Array.IndexOf(headers, "normalizedusername")].Trim('"').Trim(),
SecurityStamp = Guid.NewGuid().ToString("D"), SecurityStamp = Guid.NewGuid().ToString("D"),
PasswordHash = column[Array.IndexOf(headers, "password")].Trim('"').Trim(), // Note: This is the password PasswordHash = column[Array.IndexOf(headers, "password")].Trim('"').Trim(), // Note: This is the password
TenantId = tenantId
}; };
user.PasswordHash = _passwordHasher.HashPassword(user, user.PasswordHash); user.PasswordHash = _passwordHasher.HashPassword(user, user.PasswordHash);
@ -162,13 +169,41 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
NormalizedEmail = "DEMOUSER@MICROSOFT.COM", NormalizedEmail = "DEMOUSER@MICROSOFT.COM",
NormalizedUserName = "DEMOUSER@MICROSOFT.COM", NormalizedUserName = "DEMOUSER@MICROSOFT.COM",
SecurityStamp = Guid.NewGuid().ToString("D"), SecurityStamp = Guid.NewGuid().ToString("D"),
TenantId = 2
}; };
var user2 =
new ApplicationUser()
{
CardHolderName = "Espen",
CardNumber = "4012888888881882",
CardType = 1,
City = "Oslo",
Country = "Norway",
Email = "espent1004@gmail.com",
Expiration = "12/22",
Id = Guid.NewGuid().ToString(),
LastName = "Nordli",
Name = "Espen",
PhoneNumber = "95791135",
UserName = "espent1004@gmail.com",
ZipCode = "0681",
State = "Oslo",
Street = "Treskeveien 28A",
SecurityNumber = "535",
NormalizedEmail = "ESPENT1004@GMAIL.COM",
NormalizedUserName = "ESPENT1004@GMAIL.COM",
SecurityStamp = Guid.NewGuid().ToString("D"),
TenantId = 1
};
user.PasswordHash = _passwordHasher.HashPassword(user, "Pass@word1"); user.PasswordHash = _passwordHasher.HashPassword(user, "Pass@word1");
user2.PasswordHash = _passwordHasher.HashPassword(user2, "passord");
return new List<ApplicationUser>() return new List<ApplicationUser>()
{ {
user user,
user2
}; };
} }

View File

@ -29,6 +29,9 @@ namespace Identity.API.Migrations
b.Property<string>("CardHolderName") b.Property<string>("CardHolderName")
.IsRequired(); .IsRequired();
b.Property<int>("TenantId")
.IsRequired();
b.Property<string>("CardNumber") b.Property<string>("CardNumber")
.IsRequired(); .IsRequired();

View File

@ -53,7 +53,8 @@ namespace Identity.API.Migrations
Street = table.Column<string>(type: "nvarchar(max)", nullable: false), Street = table.Column<string>(type: "nvarchar(max)", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false), TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true), UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
ZipCode = table.Column<string>(type: "nvarchar(max)", nullable: false) ZipCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
TenantId = table.Column<int>(type: "int", nullable: false),
}, },
constraints: table => constraints: table =>
{ {

View File

@ -24,6 +24,9 @@ namespace Identity.API.Migrations
b.Property<int>("AccessFailedCount"); b.Property<int>("AccessFailedCount");
b.Property<int>("TenantId")
.IsRequired();
b.Property<string>("CardHolderName") b.Property<string>("CardHolderName")
.IsRequired(); .IsRequired();

View File

@ -30,5 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Models
public string Name { get; set; } public string Name { get; set; }
[Required] [Required]
public string LastName { get; set; } public string LastName { get; set; }
[Required]
public int TenantId { get; set; }
} }
} }

View File

@ -1,2 +1,3 @@
CardHolderName,CardNumber,CardType,City,Country,Email,Expiration,LastName,Name,PhoneNumber,UserName,ZipCode,State,Street,SecurityNumber,NormalizedEmail,NormalizedUserName,Password CardHolderName,CardNumber,CardType,City,Country,Email,Expiration,LastName,Name,PhoneNumber,UserName,ZipCode,State,Street,SecurityNumber,NormalizedEmail,NormalizedUserName,Password,TenantId
DemoUser,4012888888881881,1,Redmond,U.S.,demouser@microsoft.com,12/20,DemoLastName,DemoUser,1234567890,demouser@microsoft.com,98052,WA,15703 NE 61st Ct,535,DEMOUSER@MICROSOFT.COM,DEMOUSER@MICROSOFT.COM,Pass@word1 DemoUser,4012888888881881,1,Redmond,U.S.,demouser@microsoft.com,12/20,DemoLastName,DemoUser,1234567890,demouser@microsoft.com,98052,WA,15703 NE 61st Ct,535,DEMOUSER@MICROSOFT.COM,DEMOUSER@MICROSOFT.COM,Pass@word1,1
Espen Nordli,4012888888881882,1,Oslo,Norway,espent1004@gmail.com,12/20,Nordli,Espen,95791135,espent1004@gmail.com,0681,Oslo,Treskeveien 28A,535,ESPENT1004@GMAIL.COM,ESPENT1004@GMAIL.COM,Pass@word1,2
1 CardHolderName CardNumber CardType City Country Email Expiration LastName Name PhoneNumber UserName ZipCode State Street SecurityNumber NormalizedEmail NormalizedUserName Password TenantId
2 DemoUser 4012888888881881 1 Redmond U.S. demouser@microsoft.com 12/20 DemoLastName DemoUser 1234567890 demouser@microsoft.com 98052 WA 15703 NE 61st Ct 535 DEMOUSER@MICROSOFT.COM DEMOUSER@MICROSOFT.COM Pass@word1 1
3 Espen Nordli 4012888888881882 1 Oslo Norway espent1004@gmail.com 12/20 Nordli Espen 95791135 espent1004@gmail.com 0681 Oslo Treskeveien 28A 535 ESPENT1004@GMAIL.COM ESPENT1004@GMAIL.COM Pass@word1 2