Microservices Tutorial Playlist Link: https://www.youtube.com/watch?v=gPInkLCfalE&list=PLzewa6pjbr3JQKhB_U_FiuYwQC70i-TyU&index=1
In this video we explains about Ocelot API Gateway Authentication. As this is an Ocelot API Gateway JWT Authentication Tutorial we are implementing, JWT authentication with Ocelot API Gateway.
Ocelot is a .NET API Gateway. This project is aimed at people using .NET running a micro services / service oriented architecture that need a unified point of entry into their system. However it will work with anything that speaks HTTP and run on any platform that ASP.NET Core supports. Ocelot is a bunch of middlewares in a specific order.
Ocelot manipulates the HttpRequest object into a state specified by its configuration until it reaches a request builder middleware where it creates a HttpRequestMessage object which is used to make a request to a downstream service. The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware. The response from the downstream service is retrieved as the requests goes back up the Ocelot pipeline. There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client. That is basically it with a bunch of other features!
There are two sections in the Ocelot API Gateway configuration. An array of Routes and a GlobalConfiguration. The Routes are the objects that tell Ocelot API Gateway, how to treat an upstream request [Ocelot API Upstream]. The Global configuration allows overrides of ReRoute specific settings. It’s useful if you don’t want to manage lots of Route specific settings.
The main functionality of an Ocelot API Gateway is to take incoming HTTP requests and forward them on to a downstream service [Ocelot API Downstream], currently as another HTTP request. Ocelot’s describes the routing of one request to another as a Route.
The DownstreamPathTemplate, Scheme, and DownstreamHostAndPorts make the internal microservice URL that this request will be forwarded to. The port is the internal port used by the service. When using containers, the port specified at its dockerfile.
The Host is a service name that depends on the service name resolution you are using. When using docker-compose, the services names are provided by the Docker Host, which is using the service names provided in the docker-compose files.
DownstreamHostAndPorts is an array that contains the host and port of any downstream services that you wish to forward requests to. Usually this configuration will just contain one entry but sometimes you might want to load balance requests to your downstream services and Ocelot lets you add more than one entry and then select a load balancer. But if using Azure and any orchestrator it is probably a better idea to load balance with the cloud and orchestrator infrastructure.
The UpstreamPathTemplate is the URL that Ocelot will use to identify which DownstreamPathTemplate to use for a given request from the client. Finally, the UpstreamHttpMethod is used so Ocelot can distinguish between different requests (GET, POST, PUT) to the same URL.
What is Docker Compose?
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
Docker for .Net Core:
.NET Core can easily run in a Docker container. Containers provide a lightweight way to isolate your application from the rest of the host system, sharing just the kernel, and using resources given to your application. Learn how to use docker for .Net Core and deploy .Net Core to Docker.
.NET Core images
Official .NET Core Docker images are published to the Microsoft Container Registry (MCR) and are discoverable at the Microsoft .NET Core Docker Hub repository. Each repository contains images for different combinations of the .NET (SDK or Runtime) and OS that you can use.
Microsoft provides images that are tailored for specific scenarios. For example, the ASP.NET Core repository provides images that are built for running ASP.NET Core apps in production.
Video Chapters:
0:00 – Video Summary
0:39 – JWT Implementation
8:12 – Authentication Web API
13:14 – Authentication from Services
14:50 – Testing Authentication from Services
16:51 – Authentication from API Gateway
18:51 – Role based Authorization in Ocelot API Gateway
20:33 – Ocelot API Gateway Rate Limiting
#codingdroplets #microservices #apigateway #microservicestutorial #microservice #docker #dotnet6 #dotnet5 #dotnetcore #aspnetcore
Comments