Webstore/SecurityWebstore/SecurityMicrosoft.AspNetCore.Identity.EntityFrameworkCoreEntityFrameworkCore.DesignEntityFrameworkCore.SqlServerAutoMapperAspNetCore.Authentication.JwtBearerUser.csRoles.csApplicationContext.csRoleConfiguration.csIdentityExtensions.csProgram.cs
```cs
| var app = builder.Build();
|| builder.Services.AddControllers(); |
| builder.Services.AddSwaggerGen(); |
| builder.Services.ConfigurePersistence(builder.Configuration); |
| builder.Services.ConfigureIdentity(); |
| builder.Services.ConfigureJWT(builder.Configuration); |
| builder.Services.ConfigureMiscellaneousServices(); |
| // Configure the HTTP request pipeline. |
| if (app.Environment.IsDevelopment()) |
| { |
| app.MapOpenApi(); |
| app.UseSwagger(); |
| app.UseSwaggerUI(); |
| } |
| app.UseAuthentication(); |
| app.UseAuthorization(); |
orderdb)
docker-compose.yml
services:
identitydb:
image: mcr.microsoft.com/mssql/server:2022-latest
volumes:
mssql_identity_data:
docker-compose.override.yml
services:
identitydb:
container_name: identitydb
environment:
- MSSQL_SA_PASSWORD=MATF12345678rs2
- ACCEPT_EULA=Y
user: root
restart: always
ports:
- "1434:1433" # NOTE different host port
volumes:
- mssql_identity_data:/var/opt/mssql
appsettings.Development.json
(NOTE the comma for port!)
"ConnectionStrings": {
"IdentityConnectionString": "Server=localhost,1434;Database=IdentityDb;User Id=sa;Password=MATF12345678rs2;TrustServerCertificate=Yes"
}
(OPTIONAL, if running dotnet-ef from CLI)
Coding
DesignTimeApplicationContextFactory.csIdentityServer -> EntityFrameworkCore -> Add Migration
CreateIdentityTablesApplicationContext$ docker-compose up -d identitydb
IdentityServer -> EntityFrameworkCore -> Update database
ApplicationContextIdentityConnectionStringDatabase Tools and SQL plugin is installed and enabled (should be by default)appsettings.Development.jsonIdentityDb -> dbo -> tables -> AspNetRolesCoding:
NewUserDto.csUserDetailsDto.csIdentityProfile.csRegistrationControllerBase.csAuthenticationController.cs
RegisterBuyer, RegisterAdministratorIdentityExtensions.cs{
"firstname": "Pera",
"lastname": "Peric",
"username": "rs2",
"password": "test1234",
"email": "razvoj.softvera.matf@gmail.com",
"phonenumber": "123-456789"
}
{
"firstname": "Ana",
"lastname": "Peric",
"username": "anaperic",
"password": "test1234",
"email": "ana.peric@matf.rs",
"phonenumber": "123-456789"
}
201appsettings.Development.json
"JwtSettings": {
"validIssuer": "Webstore Identity",
"validAudience": "Webstore",
"secretKey": "MyVerySecretMessage"
}
IdentityExtensions.cs
ConfigureJWTUserCredentialsDto.csIAuthenticationService.csAuthenticationService.cs
Program.csConfigureJWT
Овај садржај је заштићен лиценцом Creative
Commons Attribution-NonCommercial 3.0 Unported License.