Build an external api with auth using Traefik and Go

In this post I will show how to easily build an external api with authentication with help from Traefik. The usecase is the following: you want to make an external api only authenticated users can access. In this solution the authentication will be a token which clients will supply as an HTTP header. We will leverage Traefik to make the auth server and underlying api services loosely coupled. Our flow will look like this: all request to out api service will firstly be forwarded to an auth server, if the auth server responds with 200, access is granted and the clients original request will be performed. Otherwise the request from the auth server will be performed which will be an 401. We will configure Traefik to handle this routing for us. Take a look at the picture below for the flow of the request: ...

August 19, 2019 · 3 min · 472 words · Roger Welin