cuongvu0203 / tedu_exam

TEDU Exam project using DDD, CQRS, MongoDB and Identity Server 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TEDU Exam Project

Application URLs:

Docker Command Examples

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/IdentityServer/IdentityServer4.Quickstart.UI/main/getmain.ps1'))

Drop database

USE master; GO

ALTER DATABASE [Identity] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO DROP DATABASE [Identity]; GO

Packages References

Install Environment

Local secret

Exam API

{ "DatabaseSettings": { "Server": "localhost:27017", "DatabaseName": "ExamDb", "User": "admin", "Password": "Admin%40123%24" }, "IdentityUrl": "https://localhost:5001" }

Identity.Admin

{ "ConnectionStrings": { "ConfigurationDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "PersistedGrantDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "IdentityDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "AdminLogDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "AdminAuditLogDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "DataProtectionDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true" }, "AdminConfiguration": { "IdentityAdminRedirectUri": "https://localhost:6003/signin-oidc", "IdentityServerBaseUrl": "https://localhost:5001", } }

Identity.STS

{ "ConnectionStrings": { "ConfigurationDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "PersistedGrantDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "IdentityDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "DataProtectionDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true" }, "AdminConfiguration": { "IdentityAdminBaseUrl": "https://localhost:6003", } }

Admin API

{ "ConnectionStrings": { "ConfigurationDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "PersistedGrantDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "IdentityDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "AdminLogDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "AdminAuditLogDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true", "DataProtectionDbConnection": "Server=.;Database=IdentityDb;Trusted_Connection=True;MultipleActiveResultSets=true" }, "AdminApiConfiguration": { "ApiBaseUrl": "https://localhost:5003", "IdentityServerBaseUrl": "https://localhost:5001", } }

References URLS

Deploy system to IIS on Windows 10

Setup environment:

Deploy

  1. Upgrade MudBlazor
  2. Setup self certificate in IIS
  • Open file host assign new domain to 127.0.0.1: C:\windows\System32\drivers\etc
  • exam-api.local
  • identity-sts.local
  • identity-admin.local
  • admin.local
  • portal.local
  • Create new website with port 80
  • Create new SSL and Export to PFX file:

$domain= "portal.local" $password= "@OurPassword1" | ConvertTo-SecureString -AsPlainText -Force New-SelfSignedCertificate -NotBefore (Get-Date) -NotAfter (Get-Date).AddYears(1) -Subject $domain -KeyAlgorithm "RSA" -KeyLength 2048 -HashAlgorithm "SHA256" -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsage KeyEncipherment -FriendlyName $domain -TextExtension @("2.5.29.19={critical}{text}","2.5.29.37={critical}{text}1.3.6.1.5.5.7.3.1","2.5.29.17={critical}{text}DNS=$domain")

  1. Export certificate to PFX file

$domain= "portal.local" $certificate = Get-ChildItem -Path Cert:\CurrentUser\My\ | Where-Object {$_.Subject -match $domain} $password= "@OurPassword1" | ConvertTo-SecureString -AsPlainText -Force

Export-PfxCertificate -Cert $certificate -FilePath $env:USERPROFILE\Documents$domain.pfx -Password $password

  1. Trust Open MMC run: certmgr.msc --> Personal Certificate --> Copy Admin.local cert --> Paste to Trusted Root Certificate --> Certificates

  2. Import to IIS --> Server Certificate --> Import --> Choose PFX

  3. Binding to website 443 and choose certificate

  4. Click to website in IIS -> Choose SSL Setting --> Accept


Fix error (if any):

  • Check SQL and MongoDB Service in (services.msc)

  • Enable SQL Authentication --> righ click to SQL Server --> Properties

  • Change trusted connection in appsettings.json to user and password

  • Create new user in SQL for each system

  • Open connection MongoDB, create user in Mongodb: C:\Program Files\MongoDB\Server\5.0\bin\mongod.cfg security: authorization: 'enabled'

  • using UseIISIntegration() in Program.cs in ASP.NET Core

Reference: https://dev.to/iamthecarisma/managing-windows-pfx-certificates-through-powershell-3pj Powershell: Goto Current User cert: cd cert:\CurrentUser\My

About

TEDU Exam project using DDD, CQRS, MongoDB and Identity Server 4


Languages

Language:C# 57.6%Language:HTML 35.2%Language:CSS 3.4%Language:JavaScript 3.1%Language:SCSS 0.4%Language:Dockerfile 0.3%