cookie-authentication-go

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 10 Imported by: 0

README

Example of cookie authentication using go, gRPC, protobuf and mysql.

How to run

  1. Install docker and docker-compose.
  2. Run docker-compose up in the root directory of the project.
  3. The server will be running on port 3000.
  4. The client will be running on port 3001.
  5. The database will be running on port 3306.
  6. The database will be initialized with a user with email email: "test@test.com", password": "test"
  7. Request the resource /Login on the client localhost:3000/pb.v1.AuthService/Login.
  8. 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"
}

How it works

  1. The user registers with a email and password.
  2. The password is hashed using bcrypt and stored in the database.
  3. The user logs in with the email and password.
  4. The password is hashed using bcrypt and compared with the hashed password stored in the database.
  5. If the passwords match, a cookie is set with a UUID.
  6. The user can access the protected resource by sending the UUID in the cookie.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
gen
internal
common Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL