Skip to content

mikelau13/pjx-api-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pjx-api-dotnet

This repository is a group of .NET Core 3.1 dotnet core projects:

This project is one of the components of the pjx application, please check pjx-root for more details.

Pjx_Api

A simple API project developed with .Net Core 3.1, being consumed by pjx-web-react.

Dependencies

pjx-sso-identityserver - to handle the Api's authentications.

Please follow the instructions in pjx-sso-identityserver to set up the hosts and trust the self-signed SSL certificate, otherwise this API might refuse to authenticate.

Patterns

Repository Pattern, Unit of Work Pattern, Dependency Injection

For complex scenarios, Microsoft recommanded using an abstraction layer of Repository Pattern over the EF Core, although the DbContext iteslf already based on Repository pattern - https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-implementation-entity-framework-core#using-a-custom-repository-versus-using-ef-dbcontext-directly

To run

Run this command:

docker-compose up

Or run it with dotnet for local debugging:

dotnet build && dotnet run

To use with Swagger

Then you can visit the swagger UI: http://localhost:6001/swagger/ or the swagger specification: http://localhost:6001/swagger/v1/swagger.json

You will need the token to execute most of the APIs in this project, you can obtain a token from pjx-sso-identityserver, please follow the steps to register in pjx-root, login to the web page, then visit the /country/all page and get the key from the browser's developer tool.

pjx get token

Then in the swagger page, click the authorize button, paste the token Bearer xxxxxx:

pjx paste token

Then it should return successful response 200:

pjx response 200

To generate self-signed certificate for Identity Server

Execute the follow PowerShell script (but replace openssl path and output paths):

$certPass = "password"
$certSubj = "host.docker.internal"
$certAltNames = "DNS:localhost,DNS:pjx-sso-identityserver,DNS:host.docker.internal,DNS:127.0.0.1"
$opensslPath="C:\Program Files\Git\usr\bin"
$workDir="D:\Codes"
$dockerDir=Join-Path $workDir "ProjectApi"
Start-Process -NoNewWindow -Wait -FilePath (Join-Path $opensslPath "openssl.exe") -ArgumentList "req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ",
                                          (Join-Path $workDir pjx-sso-identityserver.rsa_2048.cert.key),
                                          "-out", (Join-Path $dockerDir pjx-sso-identityserver.rsa_2048.cert.crt),
                                          "-subj `"/CN=$certSubj`" -addext `"subjectAltName=$certAltNames`""
										  
Start-Process -NoNewWindow -Wait -FilePath (Join-Path $opensslPath "openssl.exe") -ArgumentList "pkcs12 -export -in ", 
                                           (Join-Path $dockerDir pjx-sso-identityserver.rsa_2048.cert.crt),
                                           "-inkey ", (Join-Path $workDir pjx-sso-identityserver.rsa_2048.cert.key),
                                           "-out ", (Join-Path $workDir pjx-sso-identityserver.rsa_2048.cert.pfx),
                                           "-passout pass:$certPass"							   
										   
#this will prompt for the password
$cert = Get-PfxCertificate -FilePath (Join-Path $workDir "pjx-sso-identityserver.rsa_2048.cert.pfx") 

Docker Hub registry

To push docker image:

docker login
docker image ls
docker tag xxxxxxxxxxxxxxxxx mikelauawaremd/pjx-api-dotnet:v0.0.yy
docker push mikelauawaremd/pjx-api-dotnet:v0.0.yy

Pull image from Docker Hub registry at mikelauawaremd/pjx-api-dotnet/v0.0.1

docker pull mikelauawaremd/pjx-api-dotnet:v0.0.1

Apply Kubernetes deployment at pjx/kubernetes/pjx-api-dotnet.yaml

kubectl apply -f pjx-web-react.yaml --namespace=pjx

About

Lightweight API gateway developed with .NET Core 3.1 C#, authenticated by pjx-sso-identityserver

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors