In this tutorial, we'll learn how to add JWT authentication to our REST API PHP application.
We'll see what JWT is and how it works. We'll also see how to get the authorization header in PHP.
We'll create REST API endpoints for allowing users to login and signup to access protected resources.
What is JWT
JWT stands for JSON Web Token and comprised of user encrypted information that can be used to authenticate users and exchange information between clients and servers.
When building REST API, instead of server sessions commonly used in PHP apps we tokens which are sent with HTTP headers from the server to clients where they are persisted (usually using local storage) then attached to every outgoing request originating from the client to the server. The server checks the token and allow or deny access to the request resource.
RESTful APIs are stateless. This means that requests from clients …
[Read more]