LeaoSomogyi / poc-ocelot

POC using Ocelot as API Gateway
5 stars 0 forks source link
api-gateway authentication authorization docker docker-compose dotnet dotnet6 gateway gateway-api jwt-authentication jwt-token ocelot ocelot-api-gateway ocelot-gateway poc-ocelot policy webapi

POC Ocelot

This project intends to be used as an example of architecture with microservices and a Gateway API using Ocelot to achieve that.

Updated to .NET 6.0 and Ocelot 18.0.0.

Give a star on Ocelot Github to support the developers!

Getting Started

git clone https://github.com/LeaoSomogyi/poc-ocelot.git

Project Architecture

This solution has five projects, only Poc.Ocelot.Gateway has exposed on docker network and this project knows how to redirect requests to another services.

This routes configurations can be found on ocelot.json file.

Take a look at the diagram:

Untitled Diagram drawio (1)

Postman

Import Poc Ocelot.postman_collection.json to Postman and follow the requests order.

0 - Auth

Service called: Poc.Ocelot.Accounts

Only request with anonymous allowed. Used to get JWT token. If you pass the permission_claim query param, your can change if this token returned can access Backoffice API's or not. Possible values for this query param: Common or Backoffice.

1 - Product List

Service called: Poc.Ocelot.Products

Just a simple get returning a message, but only requests authenticated can access. Note the authentication is provided by Gateway, none configuration is made on the project.

2 - Payment List

Service called: Poc.Ocelot.Payments

Just a simple get returning a message, but only requests authenticated can access. Note the authentication is provided by Gateway, none configuration is made on the project.

3 - Backoffice Orders

Service called: Poc.Ocelot.Backoffice

This project has your own authentication rule. Only tokens with permission claim with the value Backoffice can access this request, otherwise and status 403 is returned.

Docker

On the root folder of the solution, just run the follow command to the magic begins:

docker-compose build

Once the build was finished:

docker-compose up

To run and force build:

docker-compose up --build

Authors

Check all contributors contributors