Example of cookie authentication using go, gRPC, protobuf and mysql.
- Install docker and docker-compose.
- Run
docker-compose up
in the root directory of the project. - The server will be running on port 3000.
- The client will be running on port 3001.
- The database will be running on port 3306.
- The database will be initialized with a user with email
email: "test@test.com", password": "test"
- Request the resource
/Login
on the clientlocalhost:3000/pb.v1.AuthService/Login
. - The response will contain a cookie with a UUID.
POST /pb.v1.AuthService/Login HTTP/1.1 Host: localhost:3000 Content-Type: application/json Cache-Control: no-cache
{
"email": "test@test.com",
"password": "test"
}
- The user registers with a email and password.
- The password is hashed using bcrypt and stored in the database.
- The user logs in with the email and password.
- The password is hashed using bcrypt and compared with the hashed password stored in the database.
- If the passwords match, a cookie is set with a UUID.
- The user can access the protected resource by sending the UUID in the cookie.