System to manage leaves.
Install PostgreSQL and set up a database leave-system
and a user postgres
with password Password12!
.
Run:
cd "$env:LOCALAPPDATA\Programs\pgAdmin 4\v7\runtime"
echo '\x \\ DROP DATABASE "leave-system"; CREATE DATABASE "leave-system";' | .\psql.exe -U postgres
- Run:
docker-compose down --remove-orphans; docker-compose up -d
- Or if you have clear db:
docker-compose down --volumes; docker-compose up -d
- Or with profile:
docker-compose -f docker-compose.yml -f docker-compose.bomed.yml up -d
- Logs:
docker-compose -f docker-compose.yml -f docker-compose.bomed.yml logs -f
- Build docker image:
docker build -t leave .
- Save docker image:
docker save --output leave.tar leave
- Load docker image:
docker load --input leave.tar
- Remove all stopped containers, all dangling images, and all unused networks:
docker system prune
- Stop all containers
docker container stop $(docker container ls -aq)
- Run
docker ps
and take the image id. - Run
docker logs {image-ID} -f --tail 100
to get last 100 lines of logs.
- Clone the project
- In your Azure create
Azure Active Directory B2C
resource - Create an application. In the
Supported account types
chooseAccounts in any identity provider or organizational directory (for authenticating users with user flows)
- In the
Redirect URI (recommended)
chooseSPA
:https://localhost:7174/authentication/login-callback
- Update the
ClientId
andAuthority
in the appsettings.json
You can create a new application or use existing the Blazor Server AAD B2C
app.
- Copy client id and tenant id and paste to the
ManageAzureUsers
in the appsettings.json config file. - To to Azure Portal. Generate
client secret
. Go to the app details and clickCertificates & secrets
. ClickNew client secret
. Copy secret and paste to theManageAzureUsers/Secret
in theappsettings.json
config file. - Go to the
API permissions
,Add a permission
and addUser.ReadWrite.All
. - Click
Grant admin consent for ...
- Find Application (client) ID in the App registrations pane in the Azure portal. The app registration is named 'b2c-extensions-app. Do not modify. Used by AADB2C for storing user data.'. Copy clientId and paste to the
B2cExtensionAppClientId
.
Create new user attribute to expose custom attribute to token claims
- Open
User attributes
and add new custom attribute and name itRole
and chooseString
as a data type. Put custom description. - Go to the
User flows
and open your user flow e.g.B2C_1_signupsignin
. - Open
User attributes
and selectRole
attribute. - Do the same with
Application claims
.
-
Clone the project
-
Open a terminal and move to the directory with the project
cd LeaveSystem\LeaveSystem.Web
-
Use the Azure CLI to log in to Azure
az login --allow-no-subscriptions
-
Install msidentity-app-sync tool using command
dotnet tool install -g msidentity-app-sync
-
Register the application in Azure
msidentity-app-sync --tenant-id [tenat-id] --username [username]
E.g.
msidentity-app-sync --tenant-id 35ac175a-bb23-4b0a-8b7a-e1d55e5630f9 --username [email protected]
-
Cleanup
Program.cs
file and remove redundant line:options.ProviderOptions.DefaultAccessTokenScopes.Add("User.Read");
-
Go to Azure and find the registered application named
LeaveSystem.Web
. Open the Authentication tab and clickThis app has implicit grant settings enabled. If you are using any of these URIs in a SPA with MSAL.js 2.0, you should migrate URIs.
. -
Migrate all URLs
Run command
msidentity-app-sync --unregister true
Working with the database migrations. https://docs.microsoft.com/pl-pl/ef/core/get-started/overview/first-app?tabs=netcore-cli
Prerequisite:
- Run docker and postgress image
Run:
dotnet ef -s LeaveSystem.Api\LeaveSystem.Api\ -p LeaveSystem\LeaveSystem\ migrations add InitialCreate
dotnet ef -s LeaveSystem.Api\LeaveSystem.Api\ -p LeaveSystem\LeaveSystem\ database update
If you have issues try to install:
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
To generate new mapping I use Mapster.
Important: Mapster generate code from dll.
To regenerate mappers run:
dotnet msbuild -t:Mapster
To clear all generated files run:
dotnet msbuild -t:CleanGenerated
More info https://github.com/MapsterMapper/Mapster/wiki/Mapster.Tool.
not working, I don't know why. It is for postman
- Install Azure CLI.
- Login to the tenant, e.g.
az login -t leavesystem.onmicrosoft.com --allow-no-subscriptions
- Get access token and replace guid your scope in your server app (https://www.schaeflein.net/use-a-cli-to-get-an-access-token-for-your-aad-protected-web-api/)
az account get-access-token --resource api://4f24b978-403f-47fe-9cae-52deea03661d
If you have the following error, follow these steps:
System.ArgumentNullException: IDW10106: The 'ClientId' option must be provided.
You can find more info in documentation
- Go to
src\LeaveSystem.Api\LeaveSystem.Api
- Create
secrets.json
file with following content:
{
"AzureAdB2C:Instance": "your instance",
"AzureAdB2C:Domain": "your domain",
"AzureAdB2C:ClientId": "your client id",
"AzureAdB2C:Scopes": "your scopes",
"AzureAdB2C:SignUpSignInPolicyId": "your policy id",
"ManageAzureUsers:TenantId": "your tenat id",
"ManageAzureUsers:ClientId": "your client id",
"ManageAzureUsers:Scopes": [
"your scope"
],
"ManageAzureUsers:Secret": "your secret",
"ManageAzureUsers:B2cExtensionAppClientId": "your app client id", // Find this Application (client) ID in the App registrations pane in the Azure portal. The app registration is named 'b2c-extensions-app. Do not modify. Used by AADB2C for storing user data.'.
"ManageAzureUsers:DefaultPassword": "your default password",
"ManageAzureUsers:Issuer": "your issuer"
}
- Save secrets to store:
type .\secrets.json | dotnet user-secrets set
If you want to hot reload blazor app you have to run LeaveSystem.App and then run the command:
dotnet watch run --project LeaveSystem.Web/LeaveSystem.Web