Aditya Erlangga
Authentication with JSON Web Tokens (JWT) is a popular method for securing web applications and APIs. JWT authentication offers several benefits, such as statelessness, scalability, and easy integration with different services. Since the token contains all the necessary user information, there's no need to store session data on the server, making it scalable for distributed systems. Additionally, JWTs can be used across multiple services or microservices without the need for shared session stores, simplifying the authentication process. In Go (Golang), the Mux package is commonly used as a powerful HTTP router and middleware framework. This summary will explain how to implement JWT authentication using Golang and Mux middleware. By implementing JWT authentication using Golang and Mux middleware, you can secure your web application or API endpoints effectively. Remember to handle token expiration, revocation, and other security considerations based on your specific requirements.
On this occasion we will try to implement the use of microservices using the golang programming language in the simple case of Authentication JWT
Tools and materials that need to be prepared
Coding and Testing
This JWTMiddleware function is used to check and validate the JWT token sent by the client in the request. If the token is valid, control is passed to the next handler in the processing chain. If the token is invalid or some other error occurs in processing the token, the middleware will send an "Unauthorized" response with a relevant message.
Testing
First run the main program in the terminal
When we want to enter the API product but we haven't logged in or don't have a token, an unautorize message will appear
Then let's try to register first with the structure that was made before
and we try to log in using the account that we registered
then when we try to access api products, data will appear from that directory..
Because we have logged in and managed to get cookies in the form of tokens